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

feat: send txn without waiting for tx receipt #323

Merged
merged 3 commits into from
Aug 13, 2024
Merged
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
18 changes: 12 additions & 6 deletions chainio/clients/avsregistry/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ func (w *ChainWriter) RegisterOperatorInQuorumWithAVSRegistryCoordinator(
blsKeyPair *bls.KeyPair,
quorumNumbers types.QuorumNums,
socket string,
waitForReceipt bool,
) (*gethtypes.Receipt, error) {
operatorAddr := crypto.PubkeyToAddress(operatorEcdsaPrivateKey.PublicKey)
w.logger.Info(
Expand Down Expand Up @@ -271,7 +272,7 @@ func (w *ChainWriter) RegisterOperatorInQuorumWithAVSRegistryCoordinator(
if err != nil {
return nil, err
}
receipt, err := w.txMgr.Send(ctx, tx)
receipt, err := w.txMgr.Send(ctx, tx, waitForReceipt)
if err != nil {
return nil, errors.New("failed to send tx with err: " + err.Error())
}
Expand Down Expand Up @@ -302,6 +303,7 @@ func (w *ChainWriter) RegisterOperator(
blsKeyPair *bls.KeyPair,
quorumNumbers types.QuorumNums,
socket string,
waitForReceipt bool,
) (*gethtypes.Receipt, error) {
operatorAddr := crypto.PubkeyToAddress(operatorEcdsaPrivateKey.PublicKey)
w.logger.Info(
Expand Down Expand Up @@ -390,7 +392,7 @@ func (w *ChainWriter) RegisterOperator(
if err != nil {
return nil, err
}
receipt, err := w.txMgr.Send(ctx, tx)
receipt, err := w.txMgr.Send(ctx, tx, waitForReceipt)
if err != nil {
return nil, errors.New("failed to send tx with err: " + err.Error())
}
Expand All @@ -417,6 +419,7 @@ func (w *ChainWriter) UpdateStakesOfEntireOperatorSetForQuorums(
ctx context.Context,
operatorsPerQuorum [][]gethcommon.Address,
quorumNumbers types.QuorumNums,
waitForReceipt bool,
) (*gethtypes.Receipt, error) {
w.logger.Info("updating stakes for entire operator set", "quorumNumbers", quorumNumbers)
noSendTxOpts, err := w.txMgr.GetNoSendTxOpts()
Expand All @@ -431,7 +434,7 @@ func (w *ChainWriter) UpdateStakesOfEntireOperatorSetForQuorums(
if err != nil {
return nil, err
}
receipt, err := w.txMgr.Send(ctx, tx)
receipt, err := w.txMgr.Send(ctx, tx, waitForReceipt)
if err != nil {
return nil, errors.New("failed to send tx with err: " + err.Error())
}
Expand All @@ -449,6 +452,7 @@ func (w *ChainWriter) UpdateStakesOfEntireOperatorSetForQuorums(
func (w *ChainWriter) UpdateStakesOfOperatorSubsetForAllQuorums(
ctx context.Context,
operators []gethcommon.Address,
waitForReceipt bool,
) (*gethtypes.Receipt, error) {
w.logger.Info("updating stakes of operator subset for all quorums", "operators", operators)
noSendTxOpts, err := w.txMgr.GetNoSendTxOpts()
Expand All @@ -459,7 +463,7 @@ func (w *ChainWriter) UpdateStakesOfOperatorSubsetForAllQuorums(
if err != nil {
return nil, err
}
receipt, err := w.txMgr.Send(ctx, tx)
receipt, err := w.txMgr.Send(ctx, tx, waitForReceipt)
if err != nil {
return nil, errors.New("failed to send tx with err: " + err.Error())
}
Expand All @@ -477,6 +481,7 @@ func (w *ChainWriter) DeregisterOperator(
ctx context.Context,
quorumNumbers types.QuorumNums,
pubkey regcoord.BN254G1Point,
waitForReceipt bool,
) (*gethtypes.Receipt, error) {
w.logger.Info("deregistering operator with the AVS's registry coordinator")
noSendTxOpts, err := w.txMgr.GetNoSendTxOpts()
Expand All @@ -487,7 +492,7 @@ func (w *ChainWriter) DeregisterOperator(
if err != nil {
return nil, err
}
receipt, err := w.txMgr.Send(ctx, tx)
receipt, err := w.txMgr.Send(ctx, tx, waitForReceipt)
if err != nil {
return nil, errors.New("failed to send tx with err: " + err.Error())
}
Expand All @@ -502,6 +507,7 @@ func (w *ChainWriter) DeregisterOperator(
func (w *ChainWriter) UpdateSocket(
ctx context.Context,
socket types.Socket,
waitForReceipt bool,
) (*gethtypes.Receipt, error) {
noSendTxOpts, err := w.txMgr.GetNoSendTxOpts()
if err != nil {
Expand All @@ -511,7 +517,7 @@ func (w *ChainWriter) UpdateSocket(
if err != nil {
return nil, err
}
receipt, err := w.txMgr.Send(ctx, tx)
receipt, err := w.txMgr.Send(ctx, tx, waitForReceipt)
if err != nil {
return nil, errors.New("failed to send UpdateSocket tx with err: " + err.Error())
}
Expand Down
33 changes: 22 additions & 11 deletions chainio/clients/elcontracts/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ func NewWriterFromConfig(
), nil
}

func (w *ChainWriter) RegisterAsOperator(ctx context.Context, operator types.Operator) (*gethtypes.Receipt, error) {
func (w *ChainWriter) RegisterAsOperator(
ctx context.Context,
operator types.Operator,
waitForReceipt bool,
) (*gethtypes.Receipt, error) {
if w.delegationManager == nil {
return nil, errors.New("DelegationManager contract not provided")
}
Expand All @@ -177,7 +181,7 @@ func (w *ChainWriter) RegisterAsOperator(ctx context.Context, operator types.Ope
if err != nil {
return nil, err
}
receipt, err := w.txMgr.Send(ctx, tx)
receipt, err := w.txMgr.Send(ctx, tx, waitForReceipt)
if err != nil {
return nil, errors.New("failed to send tx with err: " + err.Error())
}
Expand All @@ -189,6 +193,7 @@ func (w *ChainWriter) RegisterAsOperator(ctx context.Context, operator types.Ope
func (w *ChainWriter) UpdateOperatorDetails(
ctx context.Context,
operator types.Operator,
waitForReceipt bool,
) (*gethtypes.Receipt, error) {
if w.delegationManager == nil {
return nil, errors.New("DelegationManager contract not provided")
Expand All @@ -212,7 +217,7 @@ func (w *ChainWriter) UpdateOperatorDetails(
if err != nil {
return nil, err
}
receipt, err := w.txMgr.Send(ctx, tx)
receipt, err := w.txMgr.Send(ctx, tx, waitForReceipt)
if err != nil {
return nil, errors.New("failed to send tx with err: " + err.Error())
}
Expand All @@ -227,7 +232,8 @@ func (w *ChainWriter) UpdateOperatorDetails(
return receipt, nil
}

func (w *ChainWriter) UpdateMetadataURI(ctx context.Context, uri string) (*gethtypes.Receipt, error) {
func (w *ChainWriter) UpdateMetadataURI(ctx context.Context, uri string, waitForReceipt bool,
) (*gethtypes.Receipt, error) {
if w.delegationManager == nil {
return nil, errors.New("DelegationManager contract not provided")
}
Expand All @@ -241,7 +247,7 @@ func (w *ChainWriter) UpdateMetadataURI(ctx context.Context, uri string) (*getht
if err != nil {
return nil, err
}
receipt, err := w.txMgr.Send(ctx, tx)
receipt, err := w.txMgr.Send(ctx, tx, waitForReceipt)
if err != nil {
return nil, errors.New("failed to send tx with err: " + err.Error())
}
Expand All @@ -258,6 +264,7 @@ func (w *ChainWriter) DepositERC20IntoStrategy(
ctx context.Context,
strategyAddr gethcommon.Address,
amount *big.Int,
waitForReceipt bool,
) (*gethtypes.Receipt, error) {
if w.strategyManager == nil {
return nil, errors.New("StrategyManager contract not provided")
Expand All @@ -280,7 +287,7 @@ func (w *ChainWriter) DepositERC20IntoStrategy(
if err != nil {
return nil, errors.Join(errors.New("failed to approve token transfer"), err)
}
_, err = w.txMgr.Send(ctx, tx)
_, err = w.txMgr.Send(ctx, tx, waitForReceipt)
if err != nil {
return nil, errors.New("failed to send tx with err: " + err.Error())
}
Expand All @@ -289,7 +296,7 @@ func (w *ChainWriter) DepositERC20IntoStrategy(
if err != nil {
return nil, err
}
receipt, err := w.txMgr.Send(ctx, tx)
receipt, err := w.txMgr.Send(ctx, tx, waitForReceipt)
if err != nil {
return nil, errors.New("failed to send tx with err: " + err.Error())
}
Expand All @@ -301,6 +308,7 @@ func (w *ChainWriter) DepositERC20IntoStrategy(
func (w *ChainWriter) SetClaimerFor(
ctx context.Context,
claimer gethcommon.Address,
waitForReceipt bool,
) (*gethtypes.Receipt, error) {
if w.rewardsCoordinator == nil {
return nil, errors.New("RewardsCoordinator contract not provided")
Expand All @@ -315,7 +323,7 @@ func (w *ChainWriter) SetClaimerFor(
if err != nil {
return nil, err
}
receipt, err := w.txMgr.Send(ctx, tx)
receipt, err := w.txMgr.Send(ctx, tx, waitForReceipt)
if err != nil {
return nil, utils.WrapError("failed to send tx", err)
}
Expand All @@ -327,6 +335,7 @@ func (w *ChainWriter) ProcessClaim(
ctx context.Context,
claim rewardscoordinator.IRewardsCoordinatorRewardsMerkleClaim,
earnerAddress gethcommon.Address,
waitForReceipt bool,
) (*gethtypes.Receipt, error) {
if w.rewardsCoordinator == nil {
return nil, errors.New("RewardsCoordinator contract not provided")
Expand All @@ -341,7 +350,7 @@ func (w *ChainWriter) ProcessClaim(
if err != nil {
return nil, utils.WrapError("failed to create ProcessClaim tx", err)
}
receipt, err := w.txMgr.Send(ctx, tx)
receipt, err := w.txMgr.Send(ctx, tx, waitForReceipt)
if err != nil {
return nil, utils.WrapError("failed to send tx", err)
}
Expand All @@ -355,6 +364,7 @@ func (w *ChainWriter) ForceDeregisterFromOperatorSets(
avs gethcommon.Address,
operatorSetIds []uint32,
operatorSignature avsdirectory.ISignatureUtilsSignatureWithSaltAndExpiry,
waitForReceipt bool,
) (*gethtypes.Receipt, error) {
if w.avsDirectory == nil {
return nil, errors.New("AVSDirectory contract not provided")
Expand All @@ -377,7 +387,7 @@ func (w *ChainWriter) ForceDeregisterFromOperatorSets(
return nil, utils.WrapError("failed to create ForceDeregisterFromOperatorSets tx", err)
}

receipt, err := w.txMgr.Send(ctx, tx)
receipt, err := w.txMgr.Send(ctx, tx, waitForReceipt)
if err != nil {
return nil, utils.WrapError("failed to send tx", err)
}
Expand All @@ -390,6 +400,7 @@ func (w *ChainWriter) SetOperatorCommissionBips(
operatorSet rewardscoordinator.IAVSDirectoryOperatorSet,
rewardType uint8,
commissionBips uint16,
waitForReceipt bool,
) (*gethtypes.Receipt, error) {
if w.rewardsCoordinator == nil {
return nil, errors.New("RewardsCoordinator contract not provided")
Expand All @@ -405,7 +416,7 @@ func (w *ChainWriter) SetOperatorCommissionBips(
return nil, utils.WrapError("failed to create SetOperatorCommissionBips tx", err)
}

receipt, err := w.txMgr.Send(ctx, tx)
receipt, err := w.txMgr.Send(ctx, tx, waitForReceipt)
if err != nil {
return nil, utils.WrapError("failed to send tx", err)
}
Expand Down
6 changes: 5 additions & 1 deletion chainio/txmgr/geometric/geometric.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,11 @@ func newTxnRequest(tx *types.Transaction) *txnRequest {
// but it does not do nonce management, so the tx argument must have the correct nonce already set.
//
// Send is blocking and safe to call concurrently, so sending multiple txs in parallel is safe.
func (t *GeometricTxManager) Send(ctx context.Context, tx *types.Transaction) (*types.Receipt, error) {
func (t *GeometricTxManager) Send(
ctx context.Context,
tx *types.Transaction,
waitForReceipt bool,
) (*types.Receipt, error) {
return t.processTransaction(ctx, newTxnRequest(tx))
}

Expand Down
2 changes: 1 addition & 1 deletion chainio/txmgr/geometric/geometric_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func ExampleGeometricTxManager() {
client, txmgr := createTxMgr(anvilUrl, ecdsaPrivateKey)

tx := createTx(client, address)
_, err = txmgr.Send(context.TODO(), tx)
_, err = txmgr.Send(context.TODO(), tx, true)
if err != nil {
panic(err)
}
Expand Down
20 changes: 10 additions & 10 deletions chainio/txmgr/geometric/geometric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestGeometricTxManager(t *testing.T) {
unsignedTx := newUnsignedEthTransferTx(0, nil)
ctxWithTimeout, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
txReceipt, err := h.txmgr.Send(ctxWithTimeout, unsignedTx)
txReceipt, err := h.txmgr.Send(ctxWithTimeout, unsignedTx, true)
require.NoError(t, err)

h.validateTxReceipt(t, txReceipt)
Expand All @@ -90,7 +90,7 @@ func TestGeometricTxManager(t *testing.T) {
unsignedTx := newUnsignedEthTransferTx(0, nil)
ctxWithTimeout, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
txReceipt, err := h.txmgr.Send(ctxWithTimeout, unsignedTx)
txReceipt, err := h.txmgr.Send(ctxWithTimeout, unsignedTx, true)
require.NoError(t, err)

h.validateTxReceipt(t, txReceipt)
Expand All @@ -102,7 +102,7 @@ func TestGeometricTxManager(t *testing.T) {
unsignedTx := newUnsignedEthTransferTx(0, big.NewInt(1))
ctxWithTimeout, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
txReceipt, err := h.txmgr.Send(ctxWithTimeout, unsignedTx)
txReceipt, err := h.txmgr.Send(ctxWithTimeout, unsignedTx, true)
// ethBackend returns an error if the tx's gasFeeCap is less than the baseFeePerGas
// this test makes sure that even setting a gasFeeCap less than the baseFeePerGas in the tx (1 above) still
// works,
Expand All @@ -128,7 +128,7 @@ func TestGeometricTxManager(t *testing.T) {
g.Go(func() error {
ctxWithTimeout, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
txReceipt, err := h.txmgr.Send(ctxWithTimeout, tx)
txReceipt, err := h.txmgr.Send(ctxWithTimeout, tx, true)
if err == nil {
txReceipts[nonce] = txReceipt
}
Expand Down Expand Up @@ -157,7 +157,7 @@ func TestGeometricTxManager(t *testing.T) {
g.Go(func() error {
ctxWithTimeout, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
txReceipt, err := h.txmgr.Send(ctxWithTimeout, tx)
txReceipt, err := h.txmgr.Send(ctxWithTimeout, tx, true)
if err == nil {
txReceipts[nonce] = txReceipt
}
Expand All @@ -179,7 +179,7 @@ func TestGeometricTxManager(t *testing.T) {
tx := newUnsignedEthTransferTx(nonce, nil)
ctxWithTimeout, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
_, err := h.txmgr.Send(ctxWithTimeout, tx)
_, err := h.txmgr.Send(ctxWithTimeout, tx, true)
require.NoError(t, err)
}

Expand All @@ -191,7 +191,7 @@ func TestGeometricTxManager(t *testing.T) {
tx := newUnsignedEthTransferTx(uint64(100), nil)
ctxWithTimeout, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
_, err := h.txmgr.Send(ctxWithTimeout, tx)
_, err := h.txmgr.Send(ctxWithTimeout, tx, true)
require.Equal(t, context.DeadlineExceeded, err)

})
Expand All @@ -202,11 +202,11 @@ func TestGeometricTxManager(t *testing.T) {
unsignedTx := newUnsignedEthTransferTx(0, nil)
ctxWithTimeout, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
_, err := h.txmgr.Send(ctxWithTimeout, unsignedTx)
_, err := h.txmgr.Send(ctxWithTimeout, unsignedTx, true)
require.NoError(t, err)

unsignedTx = newUnsignedEthTransferTx(0, nil)
_, err = h.txmgr.Send(ctxWithTimeout, unsignedTx)
_, err = h.txmgr.Send(ctxWithTimeout, unsignedTx, true)
require.Error(t, err)
})
}
Expand Down Expand Up @@ -409,7 +409,7 @@ func TestGeometricTxManagerIntegration(t *testing.T) {
unsignedTx := newUnsignedEthTransferTx(0, nil)
ctxWithTimeout, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
txReceipt, err := h.txmgr.Send(ctxWithTimeout, unsignedTx)
txReceipt, err := h.txmgr.Send(ctxWithTimeout, unsignedTx, true)
require.NoError(t, err)

h.validateTxReceipt(t, txReceipt)
Expand Down
Loading