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

Fixed #422 : The infinite loop issue when signing using fireblocks #423

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions chainio/clients/mocks/wallet.go

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

4 changes: 4 additions & 0 deletions chainio/clients/wallet/fireblocks_wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ func NewFireblocksWallet(
}, nil
}

func (t *fireblocksWallet) IsHexTxID() bool {
return false
}

func (t *fireblocksWallet) getAccount(ctx context.Context) (*fireblocks.VaultAccount, error) {
if t.account == nil {
accounts, err := t.fireblocksClient.ListVaultAccounts(ctx)
Expand Down
4 changes: 4 additions & 0 deletions chainio/clients/wallet/privatekey_wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ func NewPrivateKeyWallet(
}, nil
}

func (t *privateKeyWallet) IsHexTxID() bool {
return true
}

func (t *privateKeyWallet) SendTransaction(ctx context.Context, tx *types.Transaction) (TxID, error) {

t.logger.Debug("Getting signer for tx")
Expand Down
4 changes: 4 additions & 0 deletions chainio/clients/wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ type Wallet interface {
GetTransactionReceipt(ctx context.Context, txID TxID) (*types.Receipt, error)
// SenderAddress returns the address of the wallet
SenderAddress(ctx context.Context) (common.Address, error)

// IsHexTxID returns true if the transaction ID (TxID) is represented as a hexadecimal string; otherwise, false.
// Some wallets use custom formats like uuid for representing the TxID instead of raw hex
IsHexTxID() bool
}
18 changes: 12 additions & 6 deletions chainio/txmgr/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,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.wallet.IsHexTxID() {
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 +97,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 +117,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