Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make min burn amount configurable by chain #48

Merged
merged 5 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions cmd/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
cctptypes "github.com/circlefin/noble-cctp/x/cctp/types"
"github.com/spf13/cobra"
"github.com/strangelove-ventures/noble-cctp-relayer/circle"
"github.com/strangelove-ventures/noble-cctp-relayer/ethereum"
"github.com/strangelove-ventures/noble-cctp-relayer/noble"
"github.com/strangelove-ventures/noble-cctp-relayer/types"
)

Expand Down Expand Up @@ -187,32 +189,48 @@ func filterInvalidDestinationCallers(registeredDomains map[types.Domain]types.Ch
return !chain.IsDestinationCaller(msg.DestinationCaller)
}

// filterLowTransfers returns true if the amount being transfered to the destination chain is lower than the min-amount configured
func filterLowTransfers(cfg *types.Config, logger log.Logger, msg *types.MessageState) bool {
bm, err := new(cctptypes.BurnMessage).Parse(msg.MsgBody)
if err != nil {
logger.Info("This is not a burn message", "err", err)
return true
}

if bm.Amount.LT(math.NewIntFromUint64(cfg.MinAmount)) {
// TODO: not assume that "noble" is domain 4, add "domain" to the noble chain conifg
var minBurnAmount uint64
if msg.DestDomain == types.Domain(4) {
nobleCfg, ok := cfg.Chains["noble"].(*noble.ChainConfig)
if !ok {
logger.Info("chain named 'noble' not found in config, filtering transaction")
return true
}
minBurnAmount = nobleCfg.MinAmount
} else {
for _, chain := range cfg.Chains {
c, ok := chain.(*ethereum.ChainConfig)
if !ok {
// noble chain, handled above
continue
}
if c.Domain == msg.DestDomain {
minBurnAmount = c.MinAmount
}
}
}

if bm.Amount.LT(math.NewIntFromUint64(minBurnAmount)) {
logger.Info(
"Filtered tx because the transfer amount is less than the minimum allowed amount",
"dest domain", msg.DestDomain,
"source_domain", msg.SourceDomain,
"source_tx", msg.SourceTxHash,
"amount", bm.Amount,
"min_amount", cfg.MinAmount,
"min_amount", minBurnAmount,
)
return true
}

logger.Info(
"Not filtering tx due to low transfer amount",
"source_domain", msg.SourceDomain,
"source_tx", msg.SourceTxHash,
"amount", bm.Amount.Uint64(),
"min_amount", cfg.MinAmount,
)

return false
}

Expand Down
1 change: 0 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ func Parse(file string) (*types.Config, error) {
ProcessorWorkerCount: cfg.ProcessorWorkerCount,
Api: cfg.Api,
Chains: make(map[string]types.ChainConfig),
MinAmount: cfg.MinAmount,
}

for name, chain := range cfg.Chains {
Expand Down
4 changes: 4 additions & 0 deletions config/sample-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ chains:
broadcast-retries: 5 # number of times to attempt the broadcast
broadcast-retry-interval: 10 # time between retries in seconds

min-amount: 10

minter-private-key: # private key


Expand All @@ -30,6 +32,8 @@ chains:

block-queue-channel-size: 1000000 # 1000000 is a safe default, increase number if starting from a very early block

min-amount: 0

minter-private-key: # hex encoded privateKey

# source domain id -> destination domain id
Expand Down
3 changes: 3 additions & 0 deletions ethereum/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Ethereum struct {
minterAddress string
maxRetries int
retryIntervalSeconds int
minAmount uint64

mu sync.Mutex
}
Expand All @@ -45,6 +46,7 @@ func NewChain(
privateKey string,
maxRetries int,
retryIntervalSeconds int,
minAmount uint64,
) (*Ethereum, error) {
privEcdsaKey, ethereumAddress, err := GetEcdsaKeyAddress(privateKey)
if err != nil {
Expand All @@ -63,6 +65,7 @@ func NewChain(
minterAddress: ethereumAddress,
maxRetries: maxRetries,
retryIntervalSeconds: retryIntervalSeconds,
minAmount: minAmount,
}, nil
}

Expand Down
3 changes: 3 additions & 0 deletions ethereum/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type ChainConfig struct {
BroadcastRetries int `yaml:"broadcast-retries"`
BroadcastRetryInterval int `yaml:"broadcast-retry-interval"`

MinAmount uint64 `yaml:"min-amount"`

// TODO move to keyring
MinterPrivateKey string `yaml:"minter-private-key"`
}
Expand All @@ -36,5 +38,6 @@ func (c *ChainConfig) Chain(name string) (types.Chain, error) {
c.MinterPrivateKey,
c.BroadcastRetries,
c.BroadcastRetryInterval,
c.MinAmount,
)
}
3 changes: 3 additions & 0 deletions noble/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Noble struct {
maxRetries int
retryIntervalSeconds int
blockQueueChannelSize uint64
minamount uint64
boojamya marked this conversation as resolved.
Show resolved Hide resolved

mu sync.Mutex
}
Expand All @@ -51,6 +52,7 @@ func NewChain(
maxRetries int,
retryIntervalSeconds int,
blockQueueChannelSize uint64,
minAmount uint64,
) (*Noble, error) {
cc, err := cosmos.NewProvider(rpcURL)
if err != nil {
Expand Down Expand Up @@ -80,6 +82,7 @@ func NewChain(
maxRetries: maxRetries,
retryIntervalSeconds: retryIntervalSeconds,
blockQueueChannelSize: blockQueueChannelSize,
minamount: minAmount,
}, nil
}

Expand Down
3 changes: 3 additions & 0 deletions noble/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type ChainConfig struct {

BlockQueueChannelSize uint64 `yaml:"block-queue-channel-size"`

MinAmount uint64 `yaml:"min-amount"`
boojamya marked this conversation as resolved.
Show resolved Hide resolved

// TODO move to keyring
MinterPrivateKey string `yaml:"minter-private-key"`
}
Expand All @@ -38,5 +40,6 @@ func (c *ChainConfig) Chain(name string) (types.Chain, error) {
c.BroadcastRetries,
c.BroadcastRetryInterval,
c.BlockQueueChannelSize,
c.MinAmount,
)
}
2 changes: 0 additions & 2 deletions types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ type Config struct {
Api struct {
TrustedProxies []string `yaml:"trusted-proxies"`
} `yaml:"api"`
MinAmount uint64 `yaml:"min-amount"`
}

type ConfigWrapper struct {
Expand All @@ -27,7 +26,6 @@ type ConfigWrapper struct {
Api struct {
TrustedProxies []string `yaml:"trusted-proxies"`
} `yaml:"api"`
MinAmount uint64 `yaml:"min-amount"`
}

type ChainConfig interface {
Expand Down
Loading