Skip to content

Commit

Permalink
Cherrypick: Add fee estimation to wallet (kaspanet#2291)
Browse files Browse the repository at this point in the history
* Add fee estimation to wallet

* Add fee rate to kaspawallet parse

* Update go version

* Get rid of golint

* Add RBF support to wallet

* Fix bump_fee UTXO lookup and fix wrong change address

* impl storage mass as per KIP9

* Use CalculateTransactionOverallMass where needed

* Some fixes

* Minor typos

* Fix test

* update version

* BroadcastRBF -> BroadcastReplacement

* rc3

* align proto files to only use camel case (fixed on RK as well)

* Rename to FeePolicy and add MaxFee option + todo

* apply max fee constrains

* increase minChangeTarget to 10kas

* fmt

* Some fixes

* fix description: maximum -> minimum

* put min feerate check in the correct location

* Fix calculateFeeLimits nil handling

* Add validations to CLI flags

* Change to rc6

* Add checkTransactionFeeRate

* Add failed broadcast transactions on send error`

* Fix estimateFee change value

* Estimate fee correctly for --send-all

* On estimateFee always assume that the recipient has ECDSA address

* remove patch version

---------

Co-authored-by: Michael Sutton <[email protected]>
  • Loading branch information
2 people authored and Toni Lukkaroinen committed Oct 30, 2024
1 parent 8554694 commit 2a8c3a8
Show file tree
Hide file tree
Showing 58 changed files with 7,137 additions and 1,624 deletions.
12 changes: 5 additions & 7 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
name: Build and upload assets
on:
release:
types: [ published ]
types: [published]

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
os: [ubuntu-latest, windows-latest, macos-latest]
name: Building, ${{ matrix.os }}
steps:
- name: Fix CRLF on Windows
Expand All @@ -19,7 +19,6 @@ jobs:
- name: Check out code into the Go module directory
uses: actions/checkout@v2


- name: Setup Go
uses: actions/setup-go@v2
with:
Expand All @@ -31,7 +30,7 @@ jobs:
# `-tags netgo,osusergo` means use pure go replacements for "os/user" and "net"
# `-s -w` strips the binary to produce smaller size binaries
run: |
go build -v -ldflags="-s -w -extldflags=-static" -tags netgo,osusergo -o ./bin/ . ./cmd/...
go build -v -ldflags="-s -w -extldflags=-static" -tags netgo,osusergo -o ./bin/ ./cmd/...
archive="bin/htnd-${{ github.event.release.tag_name }}-linux.zip"
asset_name="htnd-${{ github.event.release.tag_name }}-linux.zip"
zip -r "${archive}" ./bin/*
Expand All @@ -42,7 +41,7 @@ jobs:
if: runner.os == 'Windows'
shell: bash
run: |
go build -v -ldflags="-s -w" -o bin/ . ./cmd/...
go build -v -ldflags="-s -w" -o bin/ ./cmd/...
archive="bin/htnd-${{ github.event.release.tag_name }}-win64.zip"
asset_name="htnd-${{ github.event.release.tag_name }}-win64.zip"
powershell "Compress-Archive bin/* \"${archive}\""
Expand All @@ -52,14 +51,13 @@ jobs:
- name: Build on MacOS
if: runner.os == 'macOS'
run: |
go build -v -ldflags="-s -w" -o ./bin/ . ./cmd/...
go build -v -ldflags="-s -w" -o ./bin/ ./cmd/...
archive="bin/htnd-${{ github.event.release.tag_name }}-osx.zip"
asset_name="htnd-${{ github.event.release.tag_name }}-osx.zip"
zip -r "${archive}" ./bin/*
echo "archive=${archive}" >> $GITHUB_ENV
echo "asset_name=${asset_name}" >> $GITHUB_ENV
- name: Upload release asset
uses: actions/upload-release-asset@v1
env:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/race.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
branch: [ master, latest ]
branch: [master, latest]
name: Race detection on ${{ matrix.branch }}
steps:
- name: Check out code into the Go module directory
Expand All @@ -22,7 +22,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.19
go-version: 1.23

- name: Set scheduled branch name
shell: bash
Expand Down
14 changes: 4 additions & 10 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ on:
types: [opened, synchronize, edited]

jobs:

build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest ]
os: [ubuntu-latest, macos-latest]
name: Tests, ${{ matrix.os }}
steps:

- name: Fix CRLF on Windows
if: runner.os == 'Windows'
run: git config --global core.autocrlf false
Expand All @@ -33,8 +31,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.19

go-version: 1.23

# Source: https://github.com/actions/cache/blob/main/examples.md#go---modules
- name: Go Cache
Expand All @@ -49,16 +46,14 @@ jobs:
shell: bash
run: ./build_and_test.sh -v


stability-test-fast:
runs-on: ubuntu-latest
name: Fast stability tests, ${{ github.head_ref }}
steps:

- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.19
go-version: 1.23

- name: Checkout
uses: actions/checkout@v2
Expand All @@ -75,7 +70,6 @@ jobs:
working-directory: stability-tests
run: ./install_and_test.sh


coverage:
runs-on: ubuntu-latest
name: Produce code coverage
Expand All @@ -86,7 +80,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.19
go-version: 1.23

- name: Delete the stability tests from coverage
run: rm -r stability-tests
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ _testmain.go
debug
debug.test
__debug_bin
*__debug_*

# CI
version.txt
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -- multistage docker build: stage #1: build stage
FROM golang:1.19-alpine AS build
FROM golang:1.23-alpine AS build

RUN mkdir -p /go/src/github.com/Hoosat-Oy/HTND

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Hoosat Network is an attempt at a ASIC resistant proof-of-work cryptocurrency wi

## Requirements

Go 1.18 or later.
Go 1.23 or later.

## Installation

Expand Down
8 changes: 8 additions & 0 deletions app/appmessage/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ const (
CmdGetMempoolEntriesByAddressesResponseMessage
CmdGetCoinSupplyRequestMessage
CmdGetCoinSupplyResponseMessage
CmdGetFeeEstimateRequestMessage
CmdGetFeeEstimateResponseMessage
CmdSubmitTransactionReplacementRequestMessage
CmdSubmitTransactionReplacementResponseMessage
)

// ProtocolMessageCommandToString maps all MessageCommands to their string representation
Expand Down Expand Up @@ -300,6 +304,10 @@ var RPCMessageCommandToString = map[MessageCommand]string{
CmdGetMempoolEntriesByAddressesResponseMessage: "GetMempoolEntriesByAddressesResponse",
CmdGetCoinSupplyRequestMessage: "GetCoinSupplyRequest",
CmdGetCoinSupplyResponseMessage: "GetCoinSupplyResponse",
CmdGetFeeEstimateRequestMessage: "GetFeeEstimateRequest",
CmdGetFeeEstimateResponseMessage: "GetFeeEstimateResponse",
CmdSubmitTransactionReplacementRequestMessage: "SubmitTransactionReplacementRequest",
CmdSubmitTransactionReplacementResponseMessage: "SubmitTransactionReplacementResponse",
}

// Message is an interface that describes a hoosat message. A type that
Expand Down
47 changes: 47 additions & 0 deletions app/appmessage/rpc_fee_estimate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package appmessage

// GetFeeEstimateRequestMessage is an appmessage corresponding to
// its respective RPC message
type GetFeeEstimateRequestMessage struct {
baseMessage
}

// Command returns the protocol command string for the message
func (msg *GetFeeEstimateRequestMessage) Command() MessageCommand {
return CmdGetFeeEstimateRequestMessage
}

// NewGetFeeEstimateRequestMessage returns a instance of the message
func NewGetFeeEstimateRequestMessage() *GetFeeEstimateRequestMessage {
return &GetFeeEstimateRequestMessage{}
}

type RPCFeeRateBucket struct {
Feerate float64
EstimatedSeconds float64
}

type RPCFeeEstimate struct {
PriorityBucket RPCFeeRateBucket
NormalBuckets []RPCFeeRateBucket
LowBuckets []RPCFeeRateBucket
}

// GetCoinSupplyResponseMessage is an appmessage corresponding to
// its respective RPC message
type GetFeeEstimateResponseMessage struct {
baseMessage
Estimate RPCFeeEstimate

Error *RPCError
}

// Command returns the protocol command string for the message
func (msg *GetFeeEstimateResponseMessage) Command() MessageCommand {
return CmdGetFeeEstimateResponseMessage
}

// NewGetFeeEstimateResponseMessage returns a instance of the message
func NewGetFeeEstimateResponseMessage() *GetFeeEstimateResponseMessage {
return &GetFeeEstimateResponseMessage{}
}
42 changes: 42 additions & 0 deletions app/appmessage/rpc_submit_transaction_replacement.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package appmessage

// SubmitTransactionReplacementRequestMessage is an appmessage corresponding to
// its respective RPC message
type SubmitTransactionReplacementRequestMessage struct {
baseMessage
Transaction *RPCTransaction
}

// Command returns the protocol command string for the message
func (msg *SubmitTransactionReplacementRequestMessage) Command() MessageCommand {
return CmdSubmitTransactionReplacementRequestMessage
}

// NewSubmitTransactionReplacementRequestMessage returns a instance of the message
func NewSubmitTransactionReplacementRequestMessage(transaction *RPCTransaction) *SubmitTransactionReplacementRequestMessage {
return &SubmitTransactionReplacementRequestMessage{
Transaction: transaction,
}
}

// SubmitTransactionReplacementResponseMessage is an appmessage corresponding to
// its respective RPC message
type SubmitTransactionReplacementResponseMessage struct {
baseMessage
TransactionID string
ReplacedTransaction *RPCTransaction

Error *RPCError
}

// Command returns the protocol command string for the message
func (msg *SubmitTransactionReplacementResponseMessage) Command() MessageCommand {
return CmdSubmitTransactionReplacementResponseMessage
}

// NewSubmitTransactionReplacementResponseMessage returns a instance of the message
func NewSubmitTransactionReplacementResponseMessage(transactionID string) *SubmitTransactionReplacementResponseMessage {
return &SubmitTransactionReplacementResponseMessage{
TransactionID: transactionID,
}
}
3 changes: 0 additions & 3 deletions build_and_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ FLAGS=$@
go version

go get $FLAGS -t -d ./...
GO111MODULE=off go get $FLAGS golang.org/x/lint/golint
go install $FLAGS honnef.co/go/tools/cmd/staticcheck@latest

test -z "$(go fmt ./...)"

golint -set_exit_status ./...

staticcheck -checks SA4006,SA4008,SA4009,SA4010,SA5003,SA1004,SA1014,SA1021,SA1023,SA1024,SA1025,SA1026,SA1027,SA1028,SA2000,SA2001,SA2003,SA4000,SA4001,SA4003,SA4004,SA4011,SA4012,SA4013,SA4014,SA4015,SA4016,SA4017,SA4018,SA4019,SA4020,SA4021,SA4022,SA4023,SA5000,SA5002,SA5004,SA5005,SA5007,SA5008,SA5009,SA5010,SA5011,SA5012,SA6001,SA6002,SA9001,SA9002,SA9003,SA9004,SA9005,SA9006,ST1019 ./...

go build $FLAGS -o htnd .
Expand Down
10 changes: 9 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
HTND v1.0.7 - 2024-08-17
===========================

* Cherry pick work from Kaspa Golang reference node, even though it was supposed to be deprecated.
which includes: Fee estimation to wallet, Broadcast Replacement, Transaction Mass changes KIP9, and other changes.



HTND v1.0.6 - 2024-08-17
===========================

Expand Down Expand Up @@ -59,7 +67,7 @@ HTND v0.12.15 - 2023-12-16
* Fix windows asset building by increasing go version (#2245)
* Added a mainnet dnsseeder (#2247)
* Fix extract atomic swap data pushes (#2203)
* Adapt kaspawallet to support testnet 11 (#2211)
* Adapt htnwallet to support testnet 11 (#2211)
* Fix type detection in RemoveInvalidTransactions (#2252)

HTND v0.12.14 - 2023-09-26
Expand Down
4 changes: 2 additions & 2 deletions cmd/htnctl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ htnctl is an RPC client for htnd

## Requirements

Go 1.19 or later.
Go 1.23 or later.

## Installation

Expand Down Expand Up @@ -50,4 +50,4 @@ For example:
$ htnctl '{"getBlockDagInfoRequest":{}}'
```

For a list of all available requests check out the [RPC documentation](infrastructure/network/netadapter/server/grpcserver/protowire/rpc.md)
For a list of all available requests check out the [RPC documentation](infrastructure/network/netadapter/server/grpcserver/protowire/rpc.md)
2 changes: 1 addition & 1 deletion cmd/htnctl/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -- multistage docker build: stage #1: build stage
FROM golang:1.19-alpine AS build
FROM golang:1.23-alpine AS build

RUN mkdir -p /go/src/github.com/Hoosat-Oy/HTND

Expand Down
9 changes: 5 additions & 4 deletions cmd/htnminer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Hoosatminer is a CPU-based miner for htnd

## Requirements

Go 1.19 or later.
Go 1.23 or later.

## Installation

Expand All @@ -30,7 +30,7 @@ $ go install .
- Kapaminer should now be installed in `$(go env GOPATH)/bin`. If you did
not already add the bin directory to your system path during Go installation,
you are encouraged to do so now.

## Usage

The full hoosatminer configuration options can be seen with:
Expand All @@ -40,6 +40,7 @@ $ hoosatminer --help
```

But the minimum configuration needed to run it is:

```bash
$ hoosatminer --miningaddr=<YOUR_MINING_ADDRESS>
```
$ kaspaminer --miningaddr=<YOUR_MINING_ADDRESS>
```
2 changes: 1 addition & 1 deletion cmd/htnminer/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -- multistage docker build: stage #1: build stage
FROM golang:1.19-alpine AS build
FROM golang:1.23-alpine AS build

RUN mkdir -p /go/src/github.com/Hoosat-Oy/HTND

Expand Down
3 changes: 2 additions & 1 deletion cmd/htnwallet/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/Hoosat-Oy/HTND/cmd/htnwallet/daemon/client"
"github.com/Hoosat-Oy/HTND/cmd/htnwallet/daemon/pb"
"github.com/Hoosat-Oy/HTND/cmd/htnwallet/daemon/server"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -37,7 +38,7 @@ func broadcast(conf *broadcastConfig) error {
transactionsHex = strings.TrimSpace(string(transactionHexBytes))
}

transactions, err := decodeTransactionsFromHex(transactionsHex)
transactions, err := server.DecodeTransactionsFromHex(transactionsHex)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 2a8c3a8

Please sign in to comment.