Skip to content

Commit

Permalink
feat: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
joanestebanr committed Jan 20, 2025
1 parent 2402132 commit 27378f7
Show file tree
Hide file tree
Showing 8 changed files with 604 additions and 11 deletions.
46 changes: 46 additions & 0 deletions agglayer/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ type AggLayerClientGetEpochConfiguration interface {
GetEpochConfiguration() (*ClockConfiguration, error)
}

type AggLayerClientRecoveryQuerier interface {
GetLatestSettledCertificateHeader(networkID uint32) (*CertificateHeader, error)
GetLatestPendingCertificateHeader(networkID uint32) (*CertificateHeader, error)
}

// AgglayerClientInterface is the interface that defines the methods that the AggLayerClient will implement
type AgglayerClientInterface interface {
SendTx(signedTx SignedTx) (common.Hash, error)
Expand All @@ -32,6 +37,7 @@ type AgglayerClientInterface interface {
GetCertificateHeader(certificateHash common.Hash) (*CertificateHeader, error)
GetLatestKnownCertificateHeader(networkID uint32) (*CertificateHeader, error)
AggLayerClientGetEpochConfiguration
AggLayerClientRecoveryQuerier
}

// AggLayerClient is the client that will be used to interact with the AggLayer
Expand Down Expand Up @@ -180,3 +186,43 @@ func (c *AggLayerClient) GetLatestKnownCertificateHeader(networkID uint32) (*Cer

return result, nil
}

func (c *AggLayerClient) GetLatestSettledCertificateHeader(networkID uint32) (*CertificateHeader, error) {
response, err := jSONRPCCall(c.url, "interop_getLatestSettledCertificateHeader", networkID)
if err != nil {
return nil, fmt.Errorf("GetLatestSettledCertificateHeader error jSONRPCCall. Err: %w", err)
}

if response.Error != nil {
return nil, fmt.Errorf("GetLatestSettledCertificateHeader rpc returns an error: code=%d msg=%s",
response.Error.Code, response.Error.Message)
}

var result *CertificateHeader
err = json.Unmarshal(response.Result, &result)
if err != nil {
return nil, fmt.Errorf("GetLatestSettledCertificateHeader error Unmashal. Err: %w", err)
}

return result, nil
}

func (c *AggLayerClient) GetLatestPendingCertificateHeader(networkID uint32) (*CertificateHeader, error) {
response, err := jSONRPCCall(c.url, "interop_getLatestPendingCertificateHeader", networkID)
if err != nil {
return nil, fmt.Errorf("GetLatestPendingCertificateHeader error jSONRPCCall. Err: %w", err)
}

if response.Error != nil {
return nil, fmt.Errorf("GetLatestPendingCertificateHeader rpc returns an error: code=%d msg=%s",
response.Error.Code, response.Error.Message)
}

var result *CertificateHeader
err = json.Unmarshal(response.Result, &result)
if err != nil {
return nil, fmt.Errorf("GetLatestPendingCertificateHeader error Unmashal. Err: %w", err)
}

return result, nil
}
23 changes: 16 additions & 7 deletions agglayer/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import (
)

const (
testURL = "http://localhost:8080"
testURL = "http://localhost:8080"
testExploratoryURL = "http://localhost:32863"
)

func TestExploratoryClient(t *testing.T) {
t.Skip("This test is for exploratory purposes only")
sut := NewAggLayerClient("http://127.0.0.1:32781")
sut := NewAggLayerClient(testExploratoryURL)
config, err := sut.GetEpochConfiguration()
require.NoError(t, err)
require.NotNil(t, config)
Expand All @@ -29,24 +30,32 @@ func TestExploratoryClient(t *testing.T) {

func TestExploratoryGetCertificateHeader(t *testing.T) {
t.Skip("This test is exploratory and should be skipped")
aggLayerClient := NewAggLayerClient("http://localhost:32796")
aggLayerClient := NewAggLayerClient(testExploratoryURL)
certificateID := common.HexToHash("0xf153e75e24591432ac5deafaeaafba3fec0fd851261c86051b9c0d540b38c369")
certificateHeader, err := aggLayerClient.GetCertificateHeader(certificateID)
require.NoError(t, err)
fmt.Print(certificateHeader)
}
func TestExploratoryGetEpochConfiguration(t *testing.T) {
t.Skip("This test is exploratory and should be skipped")
aggLayerClient := NewAggLayerClient("http://localhost:32796")
aggLayerClient := NewAggLayerClient(testExploratoryURL)
clockConfig, err := aggLayerClient.GetEpochConfiguration()
require.NoError(t, err)
fmt.Print(clockConfig)
}

func TestExploratoryGetLatestKnownCertificateHeader(t *testing.T) {
t.Skip("This test is exploratory and should be skipped")
aggLayerClient := NewAggLayerClient("http://localhost:32843")
cert, err := aggLayerClient.GetLatestKnownCertificateHeader(1)
//t.Skip("This test is exploratory and should be skipped")

Check failure on line 48 in agglayer/client_test.go

View workflow job for this annotation

GitHub Actions / lint

commentFormatting: put a space between `//` and comment text (gocritic)
aggLayerClient := NewAggLayerClient(testExploratoryURL)
cert, err := aggLayerClient.GetLatestKnownCertificateHeader(2)
require.NoError(t, err)
fmt.Print(cert)
}

func TestExploratoryGetLatestPendingCertificateHeader(t *testing.T) {
//t.Skip("This test is exploratory and should be skipped")

Check failure on line 56 in agglayer/client_test.go

View workflow job for this annotation

GitHub Actions / lint

commentFormatting: put a space between `//` and comment text (gocritic)
aggLayerClient := NewAggLayerClient(testExploratoryURL)
cert, err := aggLayerClient.GetLatestPendingCertificateHeader(2)
require.NoError(t, err)
fmt.Print(cert)
}
Expand Down
116 changes: 116 additions & 0 deletions agglayer/mock_agglayer_client.go

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

16 changes: 12 additions & 4 deletions agglayer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,10 +733,10 @@ func (p *GenericError) Error() string {

// CertificateHeader is the structure returned by the interop_getCertificateHeader RPC call
type CertificateHeader struct {
NetworkID uint32 `json:"network_id"`
Height uint64 `json:"height"`
EpochNumber *uint64 `json:"epoch_number"`
CertificateIndex *uint64 `json:"certificate_index"`
NetworkID uint32 `json:"network_id"`
Height uint64 `json:"height"`
//EpochNumber *uint64 `json:"epoch_number"`

Check failure on line 738 in agglayer/types.go

View workflow job for this annotation

GitHub Actions / lint

commentFormatting: put a space between `//` and comment text (gocritic)
//CertificateIndex *uint64 `json:"certificate_index"`
CertificateID common.Hash `json:"certificate_id"`
PreviousLocalExitRoot *common.Hash `json:"prev_local_exit_root,omitempty"`
NewLocalExitRoot common.Hash `json:"new_local_exit_root"`
Expand All @@ -753,6 +753,14 @@ func (c *CertificateHeader) ID() string {
return fmt.Sprintf("%d/%s", c.Height, c.CertificateID.String())
}

// StatusString returns the string representation of the status
func (c *CertificateHeader) StatusString() string {
if c == nil {
return "???"
}
return c.Status.String()
}

func (c *CertificateHeader) String() string {
if c == nil {
return nilStr
Expand Down
11 changes: 11 additions & 0 deletions aggsender/aggsender.go
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,17 @@ func (a *AggSender) shouldSendCertificate() (bool, error) {

// checkLastCertificateFromAgglayer checks the last certificate from agglayer
func (a *AggSender) checkLastCertificateFromAgglayer(ctx context.Context) error {

Check failure on line 739 in aggsender/aggsender.go

View workflow job for this annotation

GitHub Actions / lint

`(*AggSender).checkLastCertificateFromAgglayer` - `ctx` is unused (unparam)
networkID := a.l2Syncer.OriginNetwork()
initialStatus, err := NewInitialStatus(a.log, networkID, a.storage, a.aggLayerClient)
if err != nil {
return fmt.Errorf("recovery: error retrieving initial status: %w", err)
}
initialStatus.LogData()
return nil
}

// checkLastCertificateFromAgglayer checks the last certificate from agglayer
func (a *AggSender) checkLastCertificateFromAgglayerOld(ctx context.Context) error {
networkID := a.l2Syncer.OriginNetwork()
a.log.Infof("recovery: checking last certificate from AggLayer for network %d", networkID)
aggLayerLastCert, err := a.aggLayerClient.GetLatestKnownCertificateHeader(networkID)
Expand Down
Loading

0 comments on commit 27378f7

Please sign in to comment.