Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • hackjealousy/thornode
  • thorchain/thornode
  • lpfloyd/thornode
  • balder7/thornode
  • Gaiieg/thornode
  • vivek.vardhan7/thornode
  • yairi.medinac/thornode
  • alessio/thornode
  • stjordanis/thornode
  • jtakalai1/thornode
  • ggulgun/thornode
  • pascaldekloe/thornode
  • n.huskisson1992/thornode
  • horacio.mlequo/thornode
  • blockx-labs/thornode
  • silverbackgodx/thornode
  • aleksbez/thornode
  • kushptl/thornode
  • difordcrypt/thornode
  • 5thdimension/thornode
  • edgarmanuelruizplasticos/thornode
  • DevLopME-Az/thornode
  • aswizzle/thornode
  • kiasaki/thornode
  • zhangliang041/thornode
  • cartersz/thornode
  • vikingshield/thornode
  • crzyazblue1/thornode
  • vkbdev/thornode
  • nathanaafo/thornode
  • bi23com_guard/thornode
  • crux25/thornode
  • TheArchitect108/thornode
  • zby121103/thornode
  • the_eridanus/thornode
  • halley9r/thornode
  • pendergrassjohn288/thornode
  • faisal1389/thornode
  • alexdcox/thornode
  • huginntc/thornode
  • guidovranken/thornode
  • thorCatStevens/thornode
  • mogarchy/thornode
  • blackprotocol/blacknode
  • pranav292gpt/thornode
  • dp49/thornode
  • Bevan96230395/thornode
  • JonathanLorimer/thornode
  • akil27/thornode
  • assafmo/thornode
  • Multipartite/thornode
  • george_s/thornode
  • thehuman/thornode
  • 0x-General/thornode
  • kaladinlight/thornode
  • oliver154/thornode
  • TreefeedXavier/thornode
  • veado/thornode
  • HooriRn/thornode
  • PaperNautilus/thornode
  • scorchedfire/thornode
  • KevinXdefi/thornode
  • canziclark24/thornode
  • GiMa-Maya/blacknode
  • ajabhishek759/thornode
  • akincibor/thornode
  • digitaldollarchain/digital-dollar-node
  • rufus.t.firefly/thornode
  • lends/thornode
  • mohs1n/thornode
  • SaifulJnU/thornode
  • SamusElderg/thornode
  • Hippocampus.web3/thornode
  • TxCorpi0x/thornode
  • ursa9r/thornode
  • mdanny1209/thornode
  • OxQuasar/thornode
  • justinvforvendetta/thornode
  • pluto_x1/thornode
  • cryptobuks/thornode
  • samyap/thornode
  • AsmundTHORSec/thornode
  • jiecut42/thornode
  • fishtail6993/thornode
  • koitsu/thornode
  • TheRagnarLodbrok/thornode
  • leonalistingservice/thornode
  • cosminl/thornode
  • zlyzol/thornode
  • inkthorchain/thornode
  • dyns/thornode
  • OKEAMAH/thornode
  • kirtixs/thornode
  • asamere/thornode
  • codehans/thornode
  • markfromdenmark/thornode
  • starsquid/thornode
  • danbryan1/thornode
  • jonreiter/thornode
  • beorn_9r/thornode
  • ahdzib/thornode
  • aper.cu/thornode
  • rekt0x/thornode
  • pharr117/thornode
  • gima-swapkit/thornode
  • proof.of.steve/thornode
  • proof.of.steve/thor-node-2
  • mayachain/thorchain/thornode
  • kocubinski/thornode
  • mattshields/thorchain/thornode
110 results
Show changes
Commits on Source (21)
Showing
with 192 additions and 162 deletions
...@@ -33,7 +33,6 @@ coverage.txt ...@@ -33,7 +33,6 @@ coverage.txt
c.out c.out
*.leveldb/ *.leveldb/
.envrc .envrc
log
blockscannertest/ blockscannertest/
*.log *.log
*.ldb *.ldb
......
...@@ -25,7 +25,7 @@ linters-settings: ...@@ -25,7 +25,7 @@ linters-settings:
exhaustivestruct: exhaustivestruct:
check-generated: false check-generated: false
staticcheck: staticcheck:
checks: ["all", "-SA1029", "-SA1019"] checks: ["all"]
revive: revive:
rules: rules:
- name: exported - name: exported
......
out *out
logs *logs
notifications *actions
actions *notifications
plugins
user_trunk.yaml
user.yaml
version: 0.1 version: 0.1
cli: cli:
version: 0.17.0-beta version: 1.0.1
lint: lint:
enabled: enabled:
- black-py@22.3.0 - git-diff-check
- flake8@4.0.1 - black@22.10.0
- gitleaks@8.2.5 - black-py@22.10.0
- flake8@5.0.4
- gitleaks@8.15.0
- gofmt@1.16.7 - gofmt@1.16.7
- golangci-lint@1.46.2 - golangci-lint@1.50.1
- hadolint@2.8.0 - hadolint@2.10.0
- isort@5.10.1 - isort@5.10.1
- markdownlint@0.30.0 - markdownlint@0.32.2
- prettier@2.5.1 - prettier@2.7.1
- shellcheck@0.8.0 - shellcheck@0.8.0
- shfmt@3.4.0 - shfmt@3.5.0
ignore: ignore:
- linters: [ALL] - linters: [ALL]
paths: paths:
...@@ -24,3 +26,16 @@ lint: ...@@ -24,3 +26,16 @@ lint:
- prettier - prettier
paths: paths:
- "test/fixtures/endpoints/auth/accounts/malformed.json" - "test/fixtures/endpoints/auth/accounts/malformed.json"
actions:
enabled:
- trunk-upgrade-available
plugins:
sources:
- id: trunk
ref: v0.0.5
uri: https://github.com/trunk-io/plugins
runtimes:
enabled:
- go@1.18.3
- node@16.14.2
- python@3.10.3
...@@ -115,6 +115,7 @@ lint-ci: ...@@ -115,6 +115,7 @@ lint-ci:
@./scripts/lint.sh @./scripts/lint.sh
@go run tools/analyze/main.go ./common/... ./constants/... ./x/... @go run tools/analyze/main.go ./common/... ./constants/... ./x/...
@./scripts/trunk check --all --no-progress --monitor=false @./scripts/trunk check --all --no-progress --monitor=false
@./scripts/lint-versions.bash
# ------------------------------ Testing ------------------------------ # ------------------------------ Testing ------------------------------
......
package app package app
import ( import (
"strings"
"github.com/rs/zerolog"
tmlog "github.com/tendermint/tendermint/libs/log" tmlog "github.com/tendermint/tendermint/libs/log"
"gitlab.com/thorchain/thornode/log"
) )
var _ tmlog.Logger = (*ThornodeLogWrapper)(nil) var _ tmlog.Logger = (*log.TendermintLogWrapper)(nil)
// ThornodeLogWrapper provides a wrapper around a zerolog.Logger instance. It implements
// Tendermint's Logger interface.
type ThornodeLogWrapper struct {
zerolog.Logger
ExcludeModules []string
}
// Info implements Tendermint's Logger interface and logs with level INFO. A set
// of key/value tuples may be provided to add context to the log. The number of
// tuples must be even and the key of the tuple must be a string.
func (z ThornodeLogWrapper) Info(msg string, keyVals ...interface{}) {
z.Logger.Info().Fields(getLogFields(keyVals...)).Msg(msg)
}
// Error implements Tendermint's Logger interface and logs with level ERR. A set
// of key/value tuples may be provided to add context to the log. The number of
// tuples must be even and the key of the tuple must be a string.
func (z ThornodeLogWrapper) Error(msg string, keyVals ...interface{}) {
z.Logger.Error().Fields(getLogFields(keyVals...)).Msg(msg)
}
// Debug implements Tendermint's Logger interface and logs with level DEBUG. A set
// of key/value tuples may be provided to add context to the log. The number of
// tuples must be even and the key of the tuple must be a string.
func (z ThornodeLogWrapper) Debug(msg string, keyVals ...interface{}) {
z.Logger.Debug().Fields(getLogFields(keyVals...)).Msg(msg)
}
// With returns a new wrapped logger with additional context provided by a set
// of key/value tuples. The number of tuples must be even and the key of the
// tuple must be a string.
func (z ThornodeLogWrapper) With(keyVals ...interface{}) tmlog.Logger {
if len(keyVals)%2 != 0 {
return ThornodeLogWrapper{
Logger: z.Logger.With().Fields(getLogFields(keyVals...)).Logger(),
ExcludeModules: z.ExcludeModules,
}
}
for i := 0; i < len(keyVals); i += 2 {
name, ok := keyVals[i].(string)
if !ok {
z.Logger.Error().Interface("key", keyVals[i]).Msg("non-string logging key provided")
}
if name != "module" {
continue
}
value, ok := keyVals[i+1].(string)
if !ok {
continue
}
for _, item := range z.ExcludeModules {
if strings.EqualFold(item, value) {
return ThornodeLogWrapper{
Logger: z.Logger.Level(zerolog.WarnLevel).With().Fields(getLogFields(keyVals...)).Logger(),
ExcludeModules: z.ExcludeModules,
}
}
}
}
return ThornodeLogWrapper{
Logger: z.Logger.With().Fields(getLogFields(keyVals...)).Logger(),
ExcludeModules: z.ExcludeModules,
}
}
func getLogFields(keyVals ...interface{}) map[string]interface{} {
if len(keyVals)%2 != 0 {
return nil
}
fields := make(map[string]interface{})
for i := 0; i < len(keyVals); i += 2 {
val, ok := keyVals[i].(string)
if ok {
fields[val] = keyVals[i+1]
}
}
return fields
}
...@@ -20,6 +20,7 @@ import ( ...@@ -20,6 +20,7 @@ import (
"gitlab.com/thorchain/thornode/bifrost/thorclient" "gitlab.com/thorchain/thornode/bifrost/thorclient"
"gitlab.com/thorchain/thornode/bifrost/thorclient/types" "gitlab.com/thorchain/thornode/bifrost/thorclient/types"
"gitlab.com/thorchain/thornode/common" "gitlab.com/thorchain/thornode/common"
"gitlab.com/thorchain/thornode/common/cosmos"
"gitlab.com/thorchain/thornode/constants" "gitlab.com/thorchain/thornode/constants"
mem "gitlab.com/thorchain/thornode/x/thorchain/memo" mem "gitlab.com/thorchain/thornode/x/thorchain/memo"
stypes "gitlab.com/thorchain/thornode/x/thorchain/types" stypes "gitlab.com/thorchain/thornode/x/thorchain/types"
...@@ -485,6 +486,42 @@ func (o *Observer) signAndSendToThorchain(txIn types.TxIn) error { ...@@ -485,6 +486,42 @@ func (o *Observer) signAndSendToThorchain(txIn types.TxIn) error {
}, bf) }, bf)
} }
// getSaversMemo returns an add or withdraw memo for a Savers Vault
// If the tx is not a valid savers tx, an empty string will be returned
// Savers tx criteria:
// - Inbound amount must be gas asset
// - Inbound amount must be greater than the Dust Threshold of the tx chain (see chain.DustThreshold())
func (o *Observer) getSaversMemo(chain common.Chain, tx types.TxInItem) string {
// Savers txs should have one Coin input
if len(tx.Coins) > 1 || len(tx.Coins) == 0 {
return ""
}
txAmt := tx.Coins[0].Amount
dustThreshold := chain.DustThreshold()
// Below dust threshold, ignore
if txAmt.LT(dustThreshold) {
return ""
}
asset := tx.Coins[0].Asset
synthAsset := asset.GetSyntheticAsset()
bps := txAmt.Sub(dustThreshold)
switch {
case bps.IsZero():
// Amount is too low, ignore
return ""
case bps.LTE(cosmos.NewUint(10_000)):
// Amount is within or includes dustThreshold + 10_000, generate withdraw memo
return fmt.Sprintf("-:%s:%s", synthAsset.String(), bps.String())
default:
// Amount is above dustThreshold + 10_000, generate add memo
return fmt.Sprintf("+:%s", synthAsset.String())
}
}
// getThorchainTxIns convert to the type thorchain expected // getThorchainTxIns convert to the type thorchain expected
// maybe in later THORNode can just refactor this to use the type in thorchain // maybe in later THORNode can just refactor this to use the type in thorchain
func (o *Observer) getThorchainTxIns(txIn types.TxIn) (stypes.ObservedTxs, error) { func (o *Observer) getThorchainTxIns(txIn types.TxIn) (stypes.ObservedTxs, error) {
...@@ -499,6 +536,16 @@ func (o *Observer) getThorchainTxIns(txIn types.TxIn) (stypes.ObservedTxs, error ...@@ -499,6 +536,16 @@ func (o *Observer) getThorchainTxIns(txIn types.TxIn) (stypes.ObservedTxs, error
o.logger.Info().Msgf("tx (%s) memo (%s) too long", item.Tx, item.Memo) o.logger.Info().Msgf("tx (%s) memo (%s) too long", item.Tx, item.Memo)
continue continue
} }
// If memo is empty, see if it is a memo-less savers add or withdraw
if strings.EqualFold(item.Memo, "") {
memo := o.getSaversMemo(txIn.Chain, item)
if !strings.EqualFold(memo, "") {
o.logger.Info().Str("memo", memo).Str("txId", item.Tx).Msg("created savers memo")
item.Memo = memo
}
}
if len(item.To) == 0 { if len(item.To) == 0 {
o.logger.Info().Msgf("tx (%s) to address is empty,ignore it", item.Tx) o.logger.Info().Msgf("tx (%s) to address is empty,ignore it", item.Tx)
continue continue
......
...@@ -462,3 +462,80 @@ func (s *ObserverSuite) TestFilterMemoFlag(c *C) { ...@@ -462,3 +462,80 @@ func (s *ObserverSuite) TestFilterMemoFlag(c *C) {
}) })
c.Assert(result, HasLen, 1) c.Assert(result, HasLen, 1)
} }
func (s *ObserverSuite) TestGetSaversMemo(c *C) {
pubkeyMgr, err := pubkeymanager.NewPubKeyManager(s.bridge, s.m)
c.Assert(err, IsNil)
obs, err := NewObserver(pubkeyMgr, map[common.Chain]chainclients.ChainClient{
common.BNBChain: s.b,
}, s.bridge, s.m, "", metrics.NewTssKeysignMetricMgr())
c.Assert(obs, NotNil)
c.Assert(err, IsNil)
busd, err := common.NewAsset("BNB.BUSD-BD1")
c.Assert(err, IsNil)
bnbSaversTx := types.TxInItem{
BlockHeight: 1024,
Tx: "tx1",
Memo: "",
Sender: thorchain.GetRandomBNBAddress().String(),
To: thorchain.GetRandomBNBAddress().String(),
Coins: common.Coins{
common.NewCoin(busd, cosmos.NewUint(1024)),
},
Gas: nil,
ObservedVaultPubKey: thorchain.GetRandomPubKey(),
}
// memo should be withdraw 1024 basis points
memo := obs.getSaversMemo(common.BNBChain, bnbSaversTx)
c.Assert(memo, Equals, "-:BNB/BUSD-BD1:1024")
// memo should be withdraw 1000 basis points
bnbSaversTx.Coins = common.NewCoins(common.NewCoin(common.BNBAsset, cosmos.NewUint(1000)))
memo = obs.getSaversMemo(common.BNBChain, bnbSaversTx)
c.Assert(memo, Equals, "-:BNB/BNB:1000")
// memo should be add
bnbSaversTx.Coins = common.NewCoins(common.NewCoin(common.BNBAsset, cosmos.NewUint(20_000)))
memo = obs.getSaversMemo(common.BNBChain, bnbSaversTx)
c.Assert(memo, Equals, "+:BNB/BNB")
btcSaversTx := types.TxInItem{
BlockHeight: 1024,
Tx: "tx1",
Memo: "",
Sender: thorchain.GetRandomBNBAddress().String(),
To: thorchain.GetRandomBNBAddress().String(),
Coins: common.Coins{
common.NewCoin(common.BTCAsset, cosmos.NewUint(1000)),
},
Gas: nil,
ObservedVaultPubKey: thorchain.GetRandomPubKey(),
}
// memo should be empty, amount not above dust threshold
memo = obs.getSaversMemo(common.BTCChain, btcSaversTx)
c.Assert(memo, Equals, "")
// memo should still be empty, amount is at the dust thresold, but you can't withdraw 0 basis points
btcSaversTx.Coins = common.NewCoins(common.NewCoin(common.BTCAsset, cosmos.NewUint(10_000)))
memo = obs.getSaversMemo(common.BTCChain, btcSaversTx)
c.Assert(memo, Equals, "")
// memo should be withdraw 500 basis points
btcSaversTx.Coins = common.NewCoins(common.NewCoin(common.BTCAsset, cosmos.NewUint(10_500)))
memo = obs.getSaversMemo(common.BTCChain, btcSaversTx)
c.Assert(memo, Equals, "-:BTC/BTC:500")
// memo should be withdraw 10_000 basis points
btcSaversTx.Coins = common.NewCoins(common.NewCoin(common.BTCAsset, cosmos.NewUint(20_000)))
memo = obs.getSaversMemo(common.BTCChain, btcSaversTx)
c.Assert(memo, Equals, "-:BTC/BTC:10000")
// memo should be add
btcSaversTx.Coins = common.NewCoins(common.NewCoin(common.BTCAsset, cosmos.NewUint(40_000)))
memo = obs.getSaversMemo(common.BTCChain, btcSaversTx)
c.Assert(memo, Equals, "+:BTC/BTC")
}
...@@ -51,7 +51,6 @@ const ( ...@@ -51,7 +51,6 @@ const (
// EstimateAverageTxSize for THORChain the estimate tx size is hard code to 1000 here , as most of time it will spend 1 input, have 3 output // EstimateAverageTxSize for THORChain the estimate tx size is hard code to 1000 here , as most of time it will spend 1 input, have 3 output
// which is average at 250 vbytes , however asgard will consolidate UTXOs , which will take up to 1000 vbytes // which is average at 250 vbytes , however asgard will consolidate UTXOs , which will take up to 1000 vbytes
EstimateAverageTxSize = 1000 EstimateAverageTxSize = 1000
DefaultCoinbaseValue = 6.25
MaxMempoolScanPerTry = 500 MaxMempoolScanPerTry = 500
) )
...@@ -880,7 +879,7 @@ func (c *Client) extractTxs(block *btcjson.GetBlockVerboseTxResult) (types.TxIn, ...@@ -880,7 +879,7 @@ func (c *Client) extractTxs(block *btcjson.GetBlockVerboseTxResult) (types.TxIn,
if txInItem.Coins.IsEmpty() { if txInItem.Coins.IsEmpty() {
continue continue
} }
if txInItem.Coins[0].Amount.LT(cosmos.NewUint(minSpendableUTXOAmountSats)) { if txInItem.Coins[0].Amount.LT(c.chain.DustThreshold()) {
continue continue
} }
exist, err := c.temporalStorage.TrackObservedTx(txInItem.Tx) exist, err := c.temporalStorage.TrackObservedTx(txInItem.Tx)
...@@ -1166,7 +1165,7 @@ func (c *Client) getBlockRequiredConfirmation(txIn types.TxIn, height int64) (in ...@@ -1166,7 +1165,7 @@ func (c *Client) getBlockRequiredConfirmation(txIn types.TxIn, height int64) (in
c.logger.Err(err).Msg("fail to get coinbase value") c.logger.Err(err).Msg("fail to get coinbase value")
} }
if totalFeeAndSubsidy == 0 { if totalFeeAndSubsidy == 0 {
cbValue, err := btcutil.NewAmount(DefaultCoinbaseValue) cbValue, err := btcutil.NewAmount(c.chain.DefaultCoinbase())
if err != nil { if err != nil {
return 0, fmt.Errorf("fail to get default coinbase value: %w", err) return 0, fmt.Errorf("fail to get default coinbase value: %w", err)
} }
......
...@@ -33,10 +33,9 @@ const ( ...@@ -33,10 +33,9 @@ const (
// SatsPervBytes it should be enough , this one will only be used if signer can't find any previous UTXO , and fee info from local storage. // SatsPervBytes it should be enough , this one will only be used if signer can't find any previous UTXO , and fee info from local storage.
SatsPervBytes = 25 SatsPervBytes = 25
// MinUTXOConfirmation UTXO that has less confirmation then this will not be spent , unless it is yggdrasil // MinUTXOConfirmation UTXO that has less confirmation then this will not be spent , unless it is yggdrasil
MinUTXOConfirmation = 1 MinUTXOConfirmation = 1
defaultMaxBTCFeeRate = btcutil.SatoshiPerBitcoin / 10 defaultMaxBTCFeeRate = btcutil.SatoshiPerBitcoin / 10
maxUTXOsToSpend = 10 maxUTXOsToSpend = 10
minSpendableUTXOAmountSats = 10000 // If UTXO is less than this , it will not observed , and will not spend it either
) )
func getBTCPrivateKey(key cryptotypes.PrivKey) (*btcec.PrivateKey, error) { func getBTCPrivateKey(key cryptotypes.PrivKey) (*btcec.PrivateKey, error) {
...@@ -122,7 +121,7 @@ func (c *Client) getUtxoToSpend(pubKey common.PubKey, total float64) ([]btcjson. ...@@ -122,7 +121,7 @@ func (c *Client) getUtxoToSpend(pubKey common.PubKey, total float64) ([]btcjson.
return utxos[i].TxID < utxos[j].TxID return utxos[i].TxID < utxos[j].TxID
}) })
var toSpend float64 var toSpend float64
minUTXOAmt := btcutil.Amount(minSpendableUTXOAmountSats).ToBTC() minUTXOAmt := btcutil.Amount(c.chain.DustThreshold().Uint64()).ToBTC()
for _, item := range utxos { for _, item := range utxos {
if !c.isValidUTXO(item.ScriptPubKey) { if !c.isValidUTXO(item.ScriptPubKey) {
c.logger.Info().Msgf("invalid UTXO , can't spent it") c.logger.Info().Msgf("invalid UTXO , can't spent it")
...@@ -135,7 +134,7 @@ func (c *Client) getUtxoToSpend(pubKey common.PubKey, total float64) ([]btcjson. ...@@ -135,7 +134,7 @@ func (c *Client) getUtxoToSpend(pubKey common.PubKey, total float64) ([]btcjson.
continue continue
} }
} }
// when the utxo is signed yggdrasil / asgard , even amount is less than minSpendableUTXOAmountSats // when the utxo is signed yggdrasil / asgard , even amount is less than DustThreshold
// it is ok to spend it // it is ok to spend it
if item.Amount < minUTXOAmt && !isSelfTx && !isYggdrasil { if item.Amount < minUTXOAmt && !isSelfTx && !isYggdrasil {
continue continue
......
...@@ -50,7 +50,6 @@ const ( ...@@ -50,7 +50,6 @@ const (
MaxAsgardAddresses = 100 MaxAsgardAddresses = 100
// EstimateAverageTxSize for THORChain the estimate tx size is hard code to 250 here , as most of time it will spend 1 input, have 3 output // EstimateAverageTxSize for THORChain the estimate tx size is hard code to 250 here , as most of time it will spend 1 input, have 3 output
EstimateAverageTxSize = 1500 EstimateAverageTxSize = 1500
DefaultCoinbaseValue = 6.25
MaxMempoolScanPerTry = 500 MaxMempoolScanPerTry = 500
) )
...@@ -864,7 +863,7 @@ func (c *Client) extractTxs(block *btcjson.GetBlockVerboseTxResult) (types.TxIn, ...@@ -864,7 +863,7 @@ func (c *Client) extractTxs(block *btcjson.GetBlockVerboseTxResult) (types.TxIn,
if txInItem.Coins.IsEmpty() { if txInItem.Coins.IsEmpty() {
continue continue
} }
if txInItem.Coins[0].Amount.LT(cosmos.NewUint(minSpendableUTXOAmountSats)) { if txInItem.Coins[0].Amount.LT(c.chain.DustThreshold()) {
continue continue
} }
exist, err := c.temporalStorage.TrackObservedTx(txInItem.Tx) exist, err := c.temporalStorage.TrackObservedTx(txInItem.Tx)
...@@ -1091,7 +1090,7 @@ func (c *Client) getBlockRequiredConfirmation(txIn types.TxIn, height int64) (in ...@@ -1091,7 +1090,7 @@ func (c *Client) getBlockRequiredConfirmation(txIn types.TxIn, height int64) (in
c.logger.Err(err).Msg("fail to get coinbase value") c.logger.Err(err).Msg("fail to get coinbase value")
} }
if totalFeeAndSubsidy == 0 { if totalFeeAndSubsidy == 0 {
cbValue, err := bchutil.NewAmount(DefaultCoinbaseValue) cbValue, err := bchutil.NewAmount(c.chain.DefaultCoinbase())
if err != nil { if err != nil {
return 0, fmt.Errorf("fail to get default coinbase value: %w", err) return 0, fmt.Errorf("fail to get default coinbase value: %w", err)
} }
......
...@@ -32,10 +32,9 @@ const ( ...@@ -32,10 +32,9 @@ const (
// SatsPervBytes it should be enough , this one will only be used if signer can't find any previous UTXO , and fee info from local storage. // SatsPervBytes it should be enough , this one will only be used if signer can't find any previous UTXO , and fee info from local storage.
SatsPervBytes = 25 SatsPervBytes = 25
// MinUTXOConfirmation UTXO that has less confirmation then this will not be spent , unless it is yggdrasil // MinUTXOConfirmation UTXO that has less confirmation then this will not be spent , unless it is yggdrasil
MinUTXOConfirmation = 1 MinUTXOConfirmation = 1
defaultMaxBCHFeeRate = bchutil.SatoshiPerBitcoin / 10 defaultMaxBCHFeeRate = bchutil.SatoshiPerBitcoin / 10
maxUTXOsToSpend = 10 maxUTXOsToSpend = 10
minSpendableUTXOAmountSats = 10000 // If UTXO is less than this , it will not observed , and will not spend it either
) )
func getBCHPrivateKey(key cryptotypes.PrivKey) (*bchec.PrivateKey, error) { func getBCHPrivateKey(key cryptotypes.PrivKey) (*bchec.PrivateKey, error) {
...@@ -123,7 +122,7 @@ func (c *Client) getUtxoToSpend(pubKey common.PubKey, total float64) ([]btcjson. ...@@ -123,7 +122,7 @@ func (c *Client) getUtxoToSpend(pubKey common.PubKey, total float64) ([]btcjson.
return utxos[i].TxID < utxos[j].TxID return utxos[i].TxID < utxos[j].TxID
}) })
var toSpend float64 var toSpend float64
minUTXOAmt := bchutil.Amount(minSpendableUTXOAmountSats).ToBCH() minUTXOAmt := bchutil.Amount(c.chain.DustThreshold().Uint64()).ToBCH()
for _, item := range utxos { for _, item := range utxos {
if !c.isValidUTXO(item.ScriptPubKey) { if !c.isValidUTXO(item.ScriptPubKey) {
c.logger.Info().Msgf("invalid UTXO , can't spent it") c.logger.Info().Msgf("invalid UTXO , can't spent it")
...@@ -136,7 +135,7 @@ func (c *Client) getUtxoToSpend(pubKey common.PubKey, total float64) ([]btcjson. ...@@ -136,7 +135,7 @@ func (c *Client) getUtxoToSpend(pubKey common.PubKey, total float64) ([]btcjson.
continue continue
} }
} }
// when the utxo is signed yggdrasil / asgard , even amount is less than minSpendableUTXOAmountSats // when the utxo is signed yggdrasil / asgard , even amount is less than DustThreshold
// it is ok to spend it // it is ok to spend it
if item.Amount < minUTXOAmt && !isSelfTx && !isYggdrasil { if item.Amount < minUTXOAmt && !isSelfTx && !isYggdrasil {
continue continue
......
...@@ -52,7 +52,6 @@ const ( ...@@ -52,7 +52,6 @@ const (
EstimateAverageTxSize = 1000 EstimateAverageTxSize = 1000
// DefaultFeePerKB is guidance set by dogecoin core team and adopted by miners: https://github.com/dogecoin/dogecoin/blob/master/doc/fee-recommendation.md // DefaultFeePerKB is guidance set by dogecoin core team and adopted by miners: https://github.com/dogecoin/dogecoin/blob/master/doc/fee-recommendation.md
DefaultFeePerKB = 0.01 DefaultFeePerKB = 0.01
DefaultCoinbaseValue = 10000
MaxMempoolScanPerTry = 500 MaxMempoolScanPerTry = 500
) )
...@@ -698,7 +697,7 @@ func (c *Client) sendNetworkFee(blockResult *btcjson.GetBlockVerboseTxResult) er ...@@ -698,7 +697,7 @@ func (c *Client) sendNetworkFee(blockResult *btcjson.GetBlockVerboseTxResult) er
if totalVSize == 0 { if totalVSize == 0 {
return nil return nil
} }
amt, err := dogutil.NewAmount(total - DefaultCoinbaseValue) amt, err := dogutil.NewAmount(total - c.chain.DefaultCoinbase())
if err != nil { if err != nil {
return fmt.Errorf("fail to parse total block fee amount,err: %w", err) return fmt.Errorf("fail to parse total block fee amount,err: %w", err)
} }
...@@ -925,7 +924,7 @@ func (c *Client) extractTxs(block *btcjson.GetBlockVerboseTxResult) (types.TxIn, ...@@ -925,7 +924,7 @@ func (c *Client) extractTxs(block *btcjson.GetBlockVerboseTxResult) (types.TxIn,
if txInItem.Coins.IsEmpty() { if txInItem.Coins.IsEmpty() {
continue continue
} }
if txInItem.Coins[0].Amount.LT(cosmos.NewUint(minSpendableUTXOAmountSats)) { if txInItem.Coins[0].Amount.LT(c.chain.DustThreshold()) {
continue continue
} }
exist, err := c.temporalStorage.TrackObservedTx(txInItem.Tx) exist, err := c.temporalStorage.TrackObservedTx(txInItem.Tx)
...@@ -1148,7 +1147,7 @@ func (c *Client) getBlockRequiredConfirmation(txIn types.TxIn, height int64) (in ...@@ -1148,7 +1147,7 @@ func (c *Client) getBlockRequiredConfirmation(txIn types.TxIn, height int64) (in
c.logger.Err(err).Msgf("fail to get coinbase value") c.logger.Err(err).Msgf("fail to get coinbase value")
} }
if totalFeeAndSubsidy == 0 { if totalFeeAndSubsidy == 0 {
cbValue, err := dogutil.NewAmount(DefaultCoinbaseValue) cbValue, err := dogutil.NewAmount(c.chain.DefaultCoinbase())
if err != nil { if err != nil {
return 0, fmt.Errorf("fail to get default coinbase value: %w", err) return 0, fmt.Errorf("fail to get default coinbase value: %w", err)
} }
......
...@@ -34,10 +34,9 @@ const ( ...@@ -34,10 +34,9 @@ const (
// SatsPervBytes it should be enough , this one will only be used if signer can't find any previous UTXO , and fee info from local storage. // SatsPervBytes it should be enough , this one will only be used if signer can't find any previous UTXO , and fee info from local storage.
SatsPervBytes = 25 SatsPervBytes = 25
// MinUTXOConfirmation UTXO that has less confirmation then this will not be spent , unless it is yggdrasil // MinUTXOConfirmation UTXO that has less confirmation then this will not be spent , unless it is yggdrasil
MinUTXOConfirmation = 1 MinUTXOConfirmation = 1
defaultMaxDOGEFeeRate = dogutil.SatoshiPerBitcoin * 10 defaultMaxDOGEFeeRate = dogutil.SatoshiPerBitcoin * 10
maxUTXOsToSpend = 10 maxUTXOsToSpend = 10
minSpendableUTXOAmountSats = 100000000 // If UTXO is less than this , it will not observed , and will not spend it either
) )
func getDOGEPrivateKey(key cryptotypes.PrivKey) (*btcec.PrivateKey, error) { func getDOGEPrivateKey(key cryptotypes.PrivKey) (*btcec.PrivateKey, error) {
...@@ -125,7 +124,7 @@ func (c *Client) getUtxoToSpend(pubKey common.PubKey, total float64) ([]btcjson. ...@@ -125,7 +124,7 @@ func (c *Client) getUtxoToSpend(pubKey common.PubKey, total float64) ([]btcjson.
return utxos[i].TxID < utxos[j].TxID return utxos[i].TxID < utxos[j].TxID
}) })
var toSpend float64 var toSpend float64
minUTXOAmt := dogutil.Amount(minSpendableUTXOAmountSats).ToBTC() minUTXOAmt := dogutil.Amount(c.chain.DustThreshold().Uint64()).ToBTC()
for _, item := range utxos { for _, item := range utxos {
if !c.isValidUTXO(item.ScriptPubKey) { if !c.isValidUTXO(item.ScriptPubKey) {
c.logger.Info().Msgf("invalid UTXO , can't spent it") c.logger.Info().Msgf("invalid UTXO , can't spent it")
...@@ -138,7 +137,7 @@ func (c *Client) getUtxoToSpend(pubKey common.PubKey, total float64) ([]btcjson. ...@@ -138,7 +137,7 @@ func (c *Client) getUtxoToSpend(pubKey common.PubKey, total float64) ([]btcjson.
continue continue
} }
} }
// when the utxo is signed by yggdrasil / asgard , even amount is less than minSpendableUTXOAmountSats // when the utxo is signed by yggdrasil / asgard , even amount is less than DustThreshold
// it is ok to spend it // it is ok to spend it
if item.Amount < minUTXOAmt && !isSelfTx && !isYggdrasil { if item.Amount < minUTXOAmt && !isSelfTx && !isYggdrasil {
continue continue
......
...@@ -32,10 +32,8 @@ func mockIsValidContractAddr(addr *ecommon.Address, _ bool) bool { ...@@ -32,10 +32,8 @@ func mockIsValidContractAddr(addr *ecommon.Address, _ bool) bool {
} }
const ( const (
// trunk-ignore-begin(gitleaks/generic-api-key)
errAssetToken = "0x983e2cC84Bb8eA7b75685F285A28Bde2b4D5aCDA" // nolint errAssetToken = "0x983e2cC84Bb8eA7b75685F285A28Bde2b4D5aCDA" // nolint
tknTestToken = "0X3B7FA4DD21C6F9BA3CA375217EAD7CAB9D6BF483" // nolint tknTestToken = "0X3B7FA4DD21C6F9BA3CA375217EAD7CAB9D6BF483" // nolint
// trunk-ignore-end(gitleaks/generic-api-key)
) )
func mockAssetResolver(token string) (common.Asset, error) { func mockAssetResolver(token string) (common.Asset, error) {
......
...@@ -49,7 +49,6 @@ const ( ...@@ -49,7 +49,6 @@ const (
MaxAsgardAddresses = 100 MaxAsgardAddresses = 100
// EstimateAverageTxSize for THORChain the estimate tx size is hard code to 250 here , as most of time it will spend 1 input, have 3 output // EstimateAverageTxSize for THORChain the estimate tx size is hard code to 250 here , as most of time it will spend 1 input, have 3 output
EstimateAverageTxSize = 250 EstimateAverageTxSize = 250
DefaultCoinbaseValue = 12.5
gasCacheBlocks = 10 gasCacheBlocks = 10
MaxMempoolScanPerTry = 500 MaxMempoolScanPerTry = 500
) )
...@@ -847,7 +846,7 @@ func (c *Client) extractTxs(block *btcjson.GetBlockVerboseTxResult) (types.TxIn, ...@@ -847,7 +846,7 @@ func (c *Client) extractTxs(block *btcjson.GetBlockVerboseTxResult) (types.TxIn,
if txInItem.Coins.IsEmpty() { if txInItem.Coins.IsEmpty() {
continue continue
} }
if txInItem.Coins[0].Amount.LT(cosmos.NewUint(minSpendableUTXOAmountSats)) { if txInItem.Coins[0].Amount.LT(c.chain.DustThreshold()) {
continue continue
} }
exist, err := c.temporalStorage.TrackObservedTx(txInItem.Tx) exist, err := c.temporalStorage.TrackObservedTx(txInItem.Tx)
...@@ -1075,7 +1074,7 @@ func (c *Client) getBlockRequiredConfirmation(txIn types.TxIn, height int64) (in ...@@ -1075,7 +1074,7 @@ func (c *Client) getBlockRequiredConfirmation(txIn types.TxIn, height int64) (in
c.logger.Err(err).Msg("fail to get coinbase value") c.logger.Err(err).Msg("fail to get coinbase value")
} }
if totalFeeAndSubsidy == 0 { if totalFeeAndSubsidy == 0 {
cbValue, err := ltcutil.NewAmount(DefaultCoinbaseValue) cbValue, err := ltcutil.NewAmount(c.chain.DefaultCoinbase())
if err != nil { if err != nil {
return 0, fmt.Errorf("fail to parse default coinbase value:%w", err) return 0, fmt.Errorf("fail to parse default coinbase value:%w", err)
} }
......
...@@ -33,10 +33,9 @@ const ( ...@@ -33,10 +33,9 @@ const (
// SatsPervBytes it should be enough , this one will only be used if signer can't find any previous UTXO , and fee info from local storage. // SatsPervBytes it should be enough , this one will only be used if signer can't find any previous UTXO , and fee info from local storage.
SatsPervBytes = 25 SatsPervBytes = 25
// MinUTXOConfirmation UTXO that has less confirmation then this will not be spent , unless it is yggdrasil // MinUTXOConfirmation UTXO that has less confirmation then this will not be spent , unless it is yggdrasil
MinUTXOConfirmation = 1 MinUTXOConfirmation = 1
defaultMaxLTCFeeRate = ltcutil.SatoshiPerBitcoin / 10 defaultMaxLTCFeeRate = ltcutil.SatoshiPerBitcoin / 10
maxUTXOsToSpend = 10 maxUTXOsToSpend = 10
minSpendableUTXOAmountSats = 10000 // If UTXO is less than this , it will not observed , and will not spend it either
) )
func getLTCPrivateKey(key cryptotypes.PrivKey) (*btcec.PrivateKey, error) { func getLTCPrivateKey(key cryptotypes.PrivKey) (*btcec.PrivateKey, error) {
...@@ -124,7 +123,7 @@ func (c *Client) getUtxoToSpend(pubKey common.PubKey, total float64) ([]btcjson. ...@@ -124,7 +123,7 @@ func (c *Client) getUtxoToSpend(pubKey common.PubKey, total float64) ([]btcjson.
return utxos[i].TxID < utxos[j].TxID return utxos[i].TxID < utxos[j].TxID
}) })
var toSpend float64 var toSpend float64
minUTXOAmt := ltcutil.Amount(minSpendableUTXOAmountSats).ToBTC() minUTXOAmt := ltcutil.Amount(c.chain.DustThreshold().Uint64()).ToBTC()
for _, item := range utxos { for _, item := range utxos {
if !c.isValidUTXO(item.ScriptPubKey) { if !c.isValidUTXO(item.ScriptPubKey) {
c.logger.Info().Msgf("invalid UTXO , can't spent it") c.logger.Info().Msgf("invalid UTXO , can't spent it")
...@@ -137,7 +136,7 @@ func (c *Client) getUtxoToSpend(pubKey common.PubKey, total float64) ([]btcjson. ...@@ -137,7 +136,7 @@ func (c *Client) getUtxoToSpend(pubKey common.PubKey, total float64) ([]btcjson.
continue continue
} }
} }
// when the utxo is signed yggdrasil / asgard , even amount is less than minSpendableUTXOAmountSats // when the utxo is signed yggdrasil / asgard , even amount is less than DustThreshold
// it is ok to spend it // it is ok to spend it
if item.Amount < minUTXOAmt && !isSelfTx && !isYggdrasil { if item.Amount < minUTXOAmt && !isSelfTx && !isYggdrasil {
continue continue
......
...@@ -32,10 +32,8 @@ func mockIsValidContractAddr(addr *ecommon.Address, _ bool) bool { ...@@ -32,10 +32,8 @@ func mockIsValidContractAddr(addr *ecommon.Address, _ bool) bool {
} }
const ( const (
// trunk-ignore-begin(gitleaks/generic-api-key) errAssetToken = "0x983e2cC84Bb8eA7b75685F285A28Bde2b4D5aCDA" // nolint gosec:G101 not a hardcoded credential
errAssetToken = "0x983e2cC84Bb8eA7b75685F285A28Bde2b4D5aCDA" // nolint tknTestToken = "0X3B7FA4DD21C6F9BA3CA375217EAD7CAB9D6BF483" // nolint gosec:G101 not a hardcoded credential
tknTestToken = "0X3B7FA4DD21C6F9BA3CA375217EAD7CAB9D6BF483" // nolint
// trunk-ignore-end(gitleaks/generic-api-key)
) )
func mockAssetResolver(token string) (common.Asset, error) { func mockAssetResolver(token string) (common.Asset, error) {
......
package types
import (
legacytypes "github.com/cosmos/cosmos-sdk/x/auth/legacy/legacytx"
cosmos "gitlab.com/thorchain/thornode/common/cosmos"
)
type SetTx struct {
Mode string `json:"mode"`
Tx struct {
Msg []cosmos.Msg `json:"msg"`
Fee legacytypes.StdFee `json:"fee"`
Signatures []legacytypes.StdSignature `json:"signatures"`
Memo string `json:"memo"`
} `json:"tx"`
}
...@@ -35,9 +35,8 @@ func (TxOutTestSuite) TestTxOutItemHash(c *C) { ...@@ -35,9 +35,8 @@ func (TxOutTestSuite) TestTxOutItemHash(c *C) {
c.Check(item.Hash(), Equals, "5037BD52845B23EEA538248622F0F9625536192A066FDCED91494171BD1EF43D") c.Check(item.Hash(), Equals, "5037BD52845B23EEA538248622F0F9625536192A066FDCED91494171BD1EF43D")
item = TxOutItem{ item = TxOutItem{
Chain: "BNB", Chain: "BNB",
ToAddress: "tbnb1yxfyeda8pnlxlmx0z3cwx74w9xevspwdpzdxpj", ToAddress: "tbnb1yxfyeda8pnlxlmx0z3cwx74w9xevspwdpzdxpj",
// trunk-ignore(gitleaks/generic-api-key)
VaultPubKey: "thorpub1addwnpepqv7kdf473gc4jyls7hlx4rg", VaultPubKey: "thorpub1addwnpepqv7kdf473gc4jyls7hlx4rg",
Memo: "REFUND:9999A5A08D8FCF942E1AAAA01AB1E521B699BA3A009FA0591C011DC1FFDC5E68", Memo: "REFUND:9999A5A08D8FCF942E1AAAA01AB1E521B699BA3A009FA0591C011DC1FFDC5E68",
InHash: "9999A5A08D8FCF942E1AAAA01AB1E521B699BA3A009FA0591C011DC1FFDC5E68", InHash: "9999A5A08D8FCF942E1AAAA01AB1E521B699BA3A009FA0591C011DC1FFDC5E68",
......