Skip to content

Commit

Permalink
[v2] Offchain integrations with v2 contracts (#960)
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-shim authored Dec 11, 2024
1 parent 3ed9ef6 commit 431be82
Show file tree
Hide file tree
Showing 10 changed files with 5,871 additions and 113 deletions.
2 changes: 1 addition & 1 deletion common/geth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func (c *EthClient) EnsureTransactionEvaled(ctx context.Context, tx *types.Trans
c.Logger.Error("Transaction Failed", "tag", tag, "txHash", tx.Hash().Hex(), "status", receipt.Status, "GasUsed", receipt.GasUsed)
return nil, ErrTransactionFailed
}
c.Logger.Debug("transaction confirmed", "txHash", tx.Hash().Hex(), "tag", tag, "gasUsed", receipt.GasUsed)
c.Logger.Debug("transaction confirmed", "txHash", tx.Hash().Hex(), "tag", tag, "gasUsed", receipt.GasUsed, "blockNumber", receipt.BlockNumber)
return receipt, nil
}

Expand Down
1,654 changes: 1,654 additions & 0 deletions contracts/bindings/EigenDABlobVerifier/binding.go

Large diffs are not rendered by default.

903 changes: 903 additions & 0 deletions contracts/bindings/EigenDARelayRegistry/binding.go

Large diffs are not rendered by default.

881 changes: 783 additions & 98 deletions contracts/bindings/EigenDAServiceManager/binding.go

Large diffs are not rendered by default.

1,761 changes: 1,761 additions & 0 deletions contracts/bindings/EigenDAThresholdRegistry/binding.go

Large diffs are not rendered by default.

687 changes: 686 additions & 1 deletion contracts/bindings/IEigenDAServiceManager/binding.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/bindings/MockRollup/binding.go

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions core/chainio.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ type Reader interface {
// GetRequiredQuorumNumbers returns set of required quorum numbers
GetRequiredQuorumNumbers(ctx context.Context, blockNumber uint32) ([]QuorumID, error)

// GetNumBlobVersions returns the number of blob versions.
GetNumBlobVersions(ctx context.Context) (uint16, error)

// GetVersionedBlobParams returns the blob version parameters for the given block number and blob version.
GetVersionedBlobParams(ctx context.Context, blobVersion uint8) (*BlobVersionParameters, error)

Expand All @@ -121,6 +124,9 @@ type Reader interface {
// GetOnDemandPaymentByAccount returns on-demand payment of an account
GetOnDemandPaymentByAccount(ctx context.Context, accountID gethcommon.Address) (*OnDemandPayment, error)

// GetNumRelays returns the number of registered relays.
GetNumRelays(ctx context.Context) (uint32, error)

// GetRelayURL returns the relay URL address for the given key.
GetRelayURL(ctx context.Context, key uint32) (string, error)

Expand Down
70 changes: 58 additions & 12 deletions core/eth/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import (
avsdir "github.com/Layr-Labs/eigenda/contracts/bindings/AVSDirectory"
blsapkreg "github.com/Layr-Labs/eigenda/contracts/bindings/BLSApkRegistry"
delegationmgr "github.com/Layr-Labs/eigenda/contracts/bindings/DelegationManager"
relayreg "github.com/Layr-Labs/eigenda/contracts/bindings/EigenDARelayRegistry"
eigendasrvmg "github.com/Layr-Labs/eigenda/contracts/bindings/EigenDAServiceManager"
thresholdreg "github.com/Layr-Labs/eigenda/contracts/bindings/EigenDAThresholdRegistry"
ejectionmg "github.com/Layr-Labs/eigenda/contracts/bindings/EjectionManager"
relayreg "github.com/Layr-Labs/eigenda/contracts/bindings/IEigenDARelayRegistry"
indexreg "github.com/Layr-Labs/eigenda/contracts/bindings/IIndexRegistry"
opstateretriever "github.com/Layr-Labs/eigenda/contracts/bindings/OperatorStateRetriever"
paymentvault "github.com/Layr-Labs/eigenda/contracts/bindings/PaymentVault"
Expand Down Expand Up @@ -41,8 +42,9 @@ type ContractBindings struct {
EjectionManager *ejectionmg.ContractEjectionManager
AVSDirectory *avsdir.ContractAVSDirectory
SocketRegistry *socketreg.ContractSocketRegistry
RelayRegistry *relayreg.ContractIEigenDARelayRegistry
PaymentVault *paymentvault.ContractPaymentVault
RelayRegistry *relayreg.ContractEigenDARelayRegistry
ThresholdRegistry *thresholdreg.ContractEigenDAThresholdRegistry
}

type Reader struct {
Expand Down Expand Up @@ -184,18 +186,30 @@ func (t *Reader) updateContractBindings(blsOperatorStateRetrieverAddr, eigenDASe
}
}

var contractRelayRegistry *relayreg.ContractIEigenDARelayRegistry
var contractRelayRegistry *relayreg.ContractEigenDARelayRegistry
relayRegistryAddr, err := contractEigenDAServiceManager.EigenDARelayRegistry(&bind.CallOpts{})
if err != nil {
t.logger.Error("Failed to fetch IEigenDARelayRegistry contract", "err", err)
// TODO(ian-shim): return err when the contract is deployed
} else {
contractRelayRegistry, err = relayreg.NewContractIEigenDARelayRegistry(relayRegistryAddr, t.ethClient)
contractRelayRegistry, err = relayreg.NewContractEigenDARelayRegistry(relayRegistryAddr, t.ethClient)
if err != nil {
t.logger.Error("Failed to fetch IEigenDARelayRegistry contract", "err", err)
}
}

var contractThresholdRegistry *thresholdreg.ContractEigenDAThresholdRegistry
thresholdRegistryAddr, err := contractEigenDAServiceManager.EigenDAThresholdRegistry(&bind.CallOpts{})
if err != nil {
t.logger.Error("Failed to fetch EigenDAThresholdRegistry contract", "err", err)
// TODO(ian-shim): return err when the contract is deployed
} else {
contractThresholdRegistry, err = thresholdreg.NewContractEigenDAThresholdRegistry(thresholdRegistryAddr, t.ethClient)
if err != nil {
t.logger.Error("Failed to fetch EigenDAThresholdRegistry contract", "err", err)
}
}

t.bindings = &ContractBindings{
ServiceManagerAddr: eigenDAServiceManagerAddr,
RegCoordinatorAddr: registryCoordinatorAddr,
Expand All @@ -211,6 +225,7 @@ func (t *Reader) updateContractBindings(blsOperatorStateRetrieverAddr, eigenDASe
DelegationManager: contractDelegationManager,
RelayRegistry: contractRelayRegistry,
// PaymentVault: contractPaymentVault,
ThresholdRegistry: contractThresholdRegistry,
}
return nil
}
Expand Down Expand Up @@ -622,6 +637,16 @@ func (t *Reader) GetRequiredQuorumNumbers(ctx context.Context, blockNumber uint3
return requiredQuorums, nil
}

func (t *Reader) GetNumBlobVersions(ctx context.Context) (uint16, error) {
if t.bindings.ThresholdRegistry == nil {
return 0, errors.New("threshold registry not deployed")
}

return t.bindings.ThresholdRegistry.NextBlobVersion(&bind.CallOpts{
Context: ctx,
})
}

func (t *Reader) GetVersionedBlobParams(ctx context.Context, blobVersion uint8) (*core.BlobVersionParameters, error) {
params, err := t.bindings.EigenDAServiceManager.GetBlobParams(&bind.CallOpts{
Context: ctx,
Expand All @@ -637,17 +662,25 @@ func (t *Reader) GetVersionedBlobParams(ctx context.Context, blobVersion uint8)
}

func (t *Reader) GetAllVersionedBlobParams(ctx context.Context) (map[uint8]*core.BlobVersionParameters, error) {
if t.bindings.ThresholdRegistry == nil {
return nil, errors.New("threshold registry not deployed")
}

numBlobVersions, err := t.GetNumBlobVersions(ctx)
if err != nil {
return nil, err
}

res := make(map[uint8]*core.BlobVersionParameters)
version := uint8(0)
for {
for version := uint8(0); version < uint8(numBlobVersions); version++ {
params, err := t.GetVersionedBlobParams(ctx, version)
if err != nil && strings.Contains(err.Error(), "execution reverted") {
break
} else if err != nil {
return nil, err
}

res[version] = params
version++
}

if len(res) == 0 {
Expand Down Expand Up @@ -821,12 +854,22 @@ func (t *Reader) GetOperatorSocket(ctx context.Context, operatorId core.Operator
return socket, nil
}

func (t *Reader) GetNumRelays(ctx context.Context) (uint32, error) {
if t.bindings.RelayRegistry == nil {
return 0, errors.New("relay registry not deployed")
}

return t.bindings.RelayRegistry.NextRelayKey(&bind.CallOpts{
Context: ctx,
})
}

func (t *Reader) GetRelayURL(ctx context.Context, key uint32) (string, error) {
if t.bindings.RelayRegistry == nil {
return "", errors.New("relay registry not deployed")
}

return t.bindings.RelayRegistry.GetRelayURL(&bind.CallOpts{
return t.bindings.RelayRegistry.RelayKeyToUrl(&bind.CallOpts{
Context: ctx,
}, uint32(key))
}
Expand All @@ -836,10 +879,14 @@ func (t *Reader) GetRelayURLs(ctx context.Context) (map[uint32]string, error) {
return nil, errors.New("relay registry not deployed")
}

numRelays, err := t.GetNumRelays(ctx)
if err != nil {
return nil, err
}

res := make(map[uint32]string)
relayKey := uint32(0)
for {
url, err := t.bindings.RelayRegistry.GetRelayURL(&bind.CallOpts{
for relayKey := uint32(0); relayKey < uint32(numRelays); relayKey++ {
url, err := t.bindings.RelayRegistry.RelayKeyToUrl(&bind.CallOpts{
Context: ctx,
}, uint32(relayKey))

Expand All @@ -850,7 +897,6 @@ func (t *Reader) GetRelayURLs(ctx context.Context) (map[uint32]string, error) {
}

res[relayKey] = url
relayKey++
}

if len(res) == 0 {
Expand Down
18 changes: 18 additions & 0 deletions core/mock/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ func (t *MockWriter) GetRequiredQuorumNumbers(ctx context.Context, blockNumber u
return result.([]uint8), args.Error(1)
}

func (t *MockWriter) GetNumBlobVersions(ctx context.Context) (uint16, error) {
args := t.Called()
result := args.Get(0)
return result.(uint16), args.Error(1)
}

func (t *MockWriter) GetVersionedBlobParams(ctx context.Context, blobVersion uint8) (*core.BlobVersionParameters, error) {
args := t.Called()
if args.Get(0) == nil {
Expand Down Expand Up @@ -251,14 +257,26 @@ func (t *MockWriter) GetOperatorSocket(ctx context.Context, operatorID core.Oper
return result.(string), args.Error(1)
}

func (t *MockWriter) GetNumRelays(ctx context.Context) (uint32, error) {
args := t.Called()
result := args.Get(0)
return result.(uint32), args.Error(1)
}

func (t *MockWriter) GetRelayURL(ctx context.Context, key uint32) (string, error) {
args := t.Called()
if args.Get(0) == nil {
return "", args.Error(1)
}
result := args.Get(0)
return result.(string), args.Error(1)
}

func (t *MockWriter) GetRelayURLs(ctx context.Context) (map[uint32]string, error) {
args := t.Called()
if args.Get(0) == nil {
return nil, args.Error(1)
}
result := args.Get(0)
if result == nil {
return nil, args.Error(1)
Expand Down

0 comments on commit 431be82

Please sign in to comment.