Skip to content

Commit

Permalink
feat: add set ejection cooldown function (#545)
Browse files Browse the repository at this point in the history
Co-authored-by: Tomás Grüner <[email protected]>
  • Loading branch information
maximopalopoli and MegaRedHand authored Feb 7, 2025
1 parent 946de36 commit 6dda27b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
24 changes: 24 additions & 0 deletions chainio/clients/avsregistry/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,3 +598,27 @@ func (w *ChainWriter) SetAccountIdentifier(
}
return receipt, nil
}

// Sets the ejection cooldown with the value received by parameter. The ejection cooldown is the time an operator has to
// wait to join any quorum after being rejected. Returns the receipt of the transaction in case of success.
func (w *ChainWriter) SetEjectionCooldown(
ctx context.Context,
ejectionCooldown *big.Int,
waitForReceipt bool,
) (*gethtypes.Receipt, error) {
w.logger.Info("setting ejection cooldown with value ", ejectionCooldown)

noSendTxOpts, err := w.txMgr.GetNoSendTxOpts()
if err != nil {
return nil, err
}
tx, err := w.registryCoordinator.SetEjectionCooldown(noSendTxOpts, ejectionCooldown)
if err != nil {
return nil, err
}
receipt, err := w.txMgr.Send(ctx, tx, waitForReceipt)
if err != nil {
return nil, utils.WrapError("failed to send SetEjectionCooldown tx with err", err.Error())
}
return receipt, nil
}
34 changes: 34 additions & 0 deletions chainio/clients/avsregistry/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,3 +603,37 @@ func TestSetAccountIdentifier(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, newAccountIdentifier.String(), testutils.ANVIL_SECOND_ADDRESS)
}

func TestSetEjectionCooldown(t *testing.T) {
// Test set up
clients, anvilHttpEndpoint := testclients.BuildTestClients(t)

contractAddrs := testutils.GetContractAddressesFromContractRegistry(anvilHttpEndpoint)

chainWriter := clients.AvsRegistryChainWriter

ejectionCooldown := big.NewInt(2873)

ethHttpClient := clients.EthHttpClient

registryCoordinatorContract, err := regcoord.NewContractRegistryCoordinator(
contractAddrs.RegistryCoordinator,
ethHttpClient,
)
require.NoError(t, err)

// At first, ejectionCooldown is zero
cooldown, err := registryCoordinatorContract.EjectionCooldown(&bind.CallOpts{})
require.NoError(t, err)
assert.Equal(t, cooldown.Int64(), int64(0))

// Set a new ejectionCooldown
receipt, err := chainWriter.SetEjectionCooldown(context.Background(), ejectionCooldown, true)
require.NoError(t, err)
require.Equal(t, receipt.Status, gethtypes.ReceiptStatusSuccessful)

// After change, ejectionCooldown is the value set
newCooldown, err := registryCoordinatorContract.EjectionCooldown(&bind.CallOpts{})
require.NoError(t, err)
assert.Equal(t, newCooldown, ejectionCooldown)
}

0 comments on commit 6dda27b

Please sign in to comment.