Skip to content

Commit

Permalink
Fixed Layr-Labs#422 Add isTxIdHex to SimpleTxManager constructor
Browse files Browse the repository at this point in the history
Introduce `isTxIdHex` to handle tx ID formats in transaction receipt retrieval. Updated relevant function signatures and logic to support this flag and added necessary changes across dependent tests and usages.
  • Loading branch information
supun-cleartoken committed Jan 6, 2025
1 parent fce9e63 commit 744c388
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion chainio/clients/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func BuildAll(
if err != nil {
return nil, utils.WrapError("Failed to create transaction sender", err)
}
txMgr := txmgr.NewSimpleTxManager(pkWallet, ethHttpClient, logger, addr)
txMgr := txmgr.NewSimpleTxManager(pkWallet, ethHttpClient, logger, addr, true)

// creating AVS clients: Reader and Writer
avsRegistryChainReader, avsRegistryChainSubscriber, avsRegistryChainWriter, avsRegistryContractBindings, err := avsregistry.BuildClients(
Expand Down
21 changes: 15 additions & 6 deletions chainio/txmgr/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type SimpleTxManager struct {
logger logging.Logger
sender common.Address
gasLimitMultiplier float64
isTxIdHex bool
}

var _ TxManager = (*SimpleTxManager)(nil)
Expand All @@ -46,13 +47,15 @@ func NewSimpleTxManager(
client ethBackend,
logger logging.Logger,
sender common.Address,
isTxIdHex bool,
) *SimpleTxManager {
return &SimpleTxManager{
wallet: wallet,
client: client,
logger: logger,
sender: sender,
gasLimitMultiplier: FallbackGasLimitMultiplier,
isTxIdHex: isTxIdHex,
}
}

Expand All @@ -74,15 +77,21 @@ func (m *SimpleTxManager) Send(
waitForReceipt bool,
) (*types.Receipt, error) {

r, err := m.send(ctx, tx)
r, txID, err := m.send(ctx, tx)
if err != nil {
return nil, errors.Join(errors.New("send: failed to estimate gas and nonce"), err)
}
if !waitForReceipt {
return r, nil
}

receipt, err := m.waitForReceipt(ctx, r.TxHash.Hex())
var receipt *types.Receipt
if m.isTxIdHex {
receipt, err = m.waitForReceipt(ctx, r.TxHash.Hex())
} else {
receipt, err = m.waitForReceipt(ctx, txID)
}

if err != nil {
log.Info("Transaction receipt not found", "err", err)
return nil, err
Expand All @@ -91,14 +100,14 @@ func (m *SimpleTxManager) Send(
return receipt, nil
}

func (m *SimpleTxManager) send(ctx context.Context, tx *types.Transaction) (*types.Receipt, error) {
func (m *SimpleTxManager) send(ctx context.Context, tx *types.Transaction) (*types.Receipt, string, error) {
// Estimate gas and nonce
// can't print tx hash in logs because the tx changes below when we complete and sign it
// so the txHash is meaningless at this point
m.logger.Debug("Estimating gas and nonce")
tx, err := m.estimateGasAndNonce(ctx, tx)
if err != nil {
return nil, err
return nil, "", err
}
bumpedGasTx := &types.DynamicFeeTx{
To: tx.To(),
Expand All @@ -111,11 +120,11 @@ func (m *SimpleTxManager) send(ctx context.Context, tx *types.Transaction) (*typ
}
txID, err := m.wallet.SendTransaction(ctx, types.NewTx(bumpedGasTx))
if err != nil {
return nil, errors.Join(errors.New("send: failed to estimate gas and nonce"), err)
return nil, "", errors.Join(errors.New("send: failed to estimate gas and nonce"), err)
}
return &types.Receipt{
TxHash: common.HexToHash(txID),
}, nil
}, txID, nil
}

func NoopSigner(addr common.Address, tx *types.Transaction) (*types.Transaction, error) {
Expand Down
2 changes: 1 addition & 1 deletion signerv2/kms_signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func TestSignTransactionWithKmsSigner(t *testing.T) {
pkWallet, err := wallet.NewPrivateKeyWallet(ethClient, signer, keyAddr, logger)
assert.Nil(t, err)
assert.NotNil(t, pkWallet)
txMgr := txmgr.NewSimpleTxManager(pkWallet, ethClient, logger, keyAddr)
txMgr := txmgr.NewSimpleTxManager(pkWallet, ethClient, logger, keyAddr, false)
assert.NotNil(t, txMgr)
receipt, err := txMgr.Send(context.Background(), gtypes.NewTx(&gtypes.DynamicFeeTx{
ChainID: &testData.Input.ChainID,
Expand Down

0 comments on commit 744c388

Please sign in to comment.