Skip to content

Commit

Permalink
Update LimitDefault and LimitMax type from uint32 to uint64 (#12307)
Browse files Browse the repository at this point in the history
* Updated LimitDefault and LimitMax type from uint32 to uint64

* Fixed linting

* Fixed integration tests

* Cleaned unnecessary uint64 conversions

* Fixed mock

* Fixed linting

* Fixed config test

* Fixed gas limit multiplier method

* Fixed linting and tests

* Fixed confirmer tests

* Fixed VRF tests

* Fixed linting

* Undid unnecessary method signature changes

* Fixed linting
  • Loading branch information
amit-momin authored Mar 6, 2024
1 parent a3870ad commit 2869a7b
Show file tree
Hide file tree
Showing 81 changed files with 304 additions and 305 deletions.
8 changes: 4 additions & 4 deletions common/fee/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
"github.com/shopspring/decimal"
)

func ApplyMultiplier(feeLimit uint32, multiplier float32) (uint32, error) {
result := decimal.NewFromBigInt(big.NewInt(0).SetUint64(uint64(feeLimit)), 0).Mul(decimal.NewFromFloat32(multiplier)).IntPart()
func ApplyMultiplier(feeLimit uint64, multiplier float32) (uint64, error) {
result := decimal.NewFromBigInt(big.NewInt(0).SetUint64(feeLimit), 0).Mul(decimal.NewFromFloat32(multiplier))

if result > math.MaxUint32 {
if result.GreaterThan(decimal.NewFromBigInt(big.NewInt(0).SetUint64(math.MaxUint64), 0)) {
return 0, fmt.Errorf("integer overflow when applying multiplier of %f to fee limit of %d", multiplier, feeLimit)
}
return uint32(result), nil
return result.BigInt().Uint64(), nil
}

// Returns the input value increased by the given percentage.
Expand Down
2 changes: 1 addition & 1 deletion common/txmgr/broadcaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ func (eb *Broadcaster[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) tryA
return eb.saveTryAgainAttempt(ctx, lgr, etx, attempt, replacementAttempt, initialBroadcastAt, fee, feeLimit)
}

func (eb *Broadcaster[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) saveTryAgainAttempt(ctx context.Context, lgr logger.Logger, etx txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE], attempt txmgrtypes.TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE], replacementAttempt txmgrtypes.TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE], initialBroadcastAt time.Time, newFee FEE, newFeeLimit uint32) (err error, retyrable bool) {
func (eb *Broadcaster[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) saveTryAgainAttempt(ctx context.Context, lgr logger.Logger, etx txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE], attempt txmgrtypes.TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE], replacementAttempt txmgrtypes.TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE], initialBroadcastAt time.Time, newFee FEE, newFeeLimit uint64) (err error, retyrable bool) {
if err = eb.txStore.SaveReplacementInProgressAttempt(ctx, attempt, &replacementAttempt); err != nil {
return fmt.Errorf("tryAgainWithNewFee failed: %w", err), true
}
Expand Down
6 changes: 3 additions & 3 deletions common/txmgr/confirmer.go
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ func (ec *Confirmer[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) bum
logFields := ec.logFieldsPreviousAttempt(previousAttempt)

var bumpedFee FEE
var bumpedFeeLimit uint32
var bumpedFeeLimit uint64
bumpedAttempt, bumpedFee, bumpedFeeLimit, _, err = ec.NewBumpTxAttempt(ctx, etx, previousAttempt, previousAttempts, ec.lggr)

// if no error, return attempt
Expand Down Expand Up @@ -1039,7 +1039,7 @@ func (ec *Confirmer[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) mar
// This operates completely orthogonal to the normal Confirmer and can result in untracked attempts!
// Only for emergency usage.
// This is in case of some unforeseen scenario where the node is refusing to release the lock. KISS.
func (ec *Confirmer[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) ForceRebroadcast(ctx context.Context, seqs []SEQ, fee FEE, address ADDR, overrideGasLimit uint32) error {
func (ec *Confirmer[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) ForceRebroadcast(ctx context.Context, seqs []SEQ, fee FEE, address ADDR, overrideGasLimit uint64) error {
if len(seqs) == 0 {
ec.lggr.Infof("ForceRebroadcast: No sequences provided. Skipping")
return nil
Expand Down Expand Up @@ -1082,7 +1082,7 @@ func (ec *Confirmer[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) For
return nil
}

func (ec *Confirmer[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) sendEmptyTransaction(ctx context.Context, fromAddress ADDR, seq SEQ, overrideGasLimit uint32, fee FEE) (string, error) {
func (ec *Confirmer[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) sendEmptyTransaction(ctx context.Context, fromAddress ADDR, seq SEQ, overrideGasLimit uint64, fee FEE) (string, error) {
gasLimit := overrideGasLimit
if gasLimit == 0 {
gasLimit = ec.feeConfig.LimitDefault()
Expand Down
2 changes: 1 addition & 1 deletion common/txmgr/txmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ func (b *Txm[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) SendNative
ToAddress: to,
EncodedPayload: []byte{},
Value: value,
FeeLimit: gasLimit,
FeeLimit: uint64(gasLimit),
Strategy: NewSendEveryStrategy(),
}
etx, err = b.pruneQueueAndCreateTxn(ctx, txRequest, chainID)
Expand Down
4 changes: 2 additions & 2 deletions common/txmgr/types/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ type TransactionClient[
) (client.SendTxReturnCode, error)
SendEmptyTransaction(
ctx context.Context,
newTxAttempt func(ctx context.Context, seq SEQ, feeLimit uint32, fee FEE, fromAddress ADDR) (attempt TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE], err error),
newTxAttempt func(ctx context.Context, seq SEQ, feeLimit uint64, fee FEE, fromAddress ADDR) (attempt TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE], err error),
seq SEQ,
gasLimit uint32,
gasLimit uint64,
fee FEE,
fromAddress ADDR,
) (txhash string, err error)
Expand Down
2 changes: 1 addition & 1 deletion common/txmgr/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type BroadcasterListenerConfig interface {

type ConfirmerFeeConfig interface {
BumpTxDepth() uint32
LimitDefault() uint32
LimitDefault() uint64

// from gas.Config
BumpThreshold() uint64
Expand Down
48 changes: 24 additions & 24 deletions common/txmgr/types/mocks/tx_attempt_builder.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2869a7b

Please sign in to comment.