Skip to content

Commit

Permalink
add new fields
Browse files Browse the repository at this point in the history
  • Loading branch information
temaniarpit27 committed Feb 5, 2025
1 parent e21993c commit 8530c98
Show file tree
Hide file tree
Showing 14 changed files with 364 additions and 300 deletions.
2 changes: 1 addition & 1 deletion agglayer/mock_agglayer_client.go

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

2 changes: 1 addition & 1 deletion agglayer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ type Certificate struct {
BridgeExits []*BridgeExit `json:"bridge_exits"`
ImportedBridgeExits []*ImportedBridgeExit `json:"imported_bridge_exits"`
Metadata common.Hash `json:"metadata"`
AggchainProof string `json:"aggchain_proof,omitempty"`
AggchainProof []byte `json:"aggchain_proof,omitempty"`
}

// Brief returns a string with a brief cert
Expand Down
6 changes: 3 additions & 3 deletions aggsender/flow_aggchain_prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ func (a *aggchainProverFlow) GetCertificateBuildParams(ctx context.Context) (*ty
proof := lastSentCertificateInfo.AggchainProof
toBlock := lastSentCertificateInfo.ToBlock

if proof == "" {
if len(proof) == 0 {
aggchainProof, err := a.aggchainProofClient.GenerateAggchainProof(lastSentCertificateInfo.FromBlock,
lastSentCertificateInfo.ToBlock, common.Hash{})
lastSentCertificateInfo.ToBlock, common.Hash{}, common.Hash{}, [32]common.Hash{})
if err != nil {
return nil, fmt.Errorf("aggchainProverFlow - error fetching aggchain proof for block range %d : %d : %w",
lastSentCertificateInfo.FromBlock, lastSentCertificateInfo.ToBlock, err)
Expand Down Expand Up @@ -117,7 +117,7 @@ func (a *aggchainProverFlow) GetCertificateBuildParams(ctx context.Context) (*ty
}

aggchainProof, err := a.aggchainProofClient.GenerateAggchainProof(
buildParams.FromBlock, buildParams.ToBlock, common.Hash{})
buildParams.FromBlock, buildParams.ToBlock, common.Hash{}, common.Hash{}, [32]common.Hash{})
if err != nil {
return nil, fmt.Errorf("aggchainProverFlow - error fetching aggchain proof for block range %d : %d : %w",
buildParams.FromBlock, buildParams.ToBlock, err)
Expand Down
32 changes: 16 additions & 16 deletions aggsender/flow_aggchain_prover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ func Test_AggchainProverFlow_GetCertificateBuildParams(t *testing.T) {
}, nil)
mockL2Syncer.On("GetBridgesPublished", ctx, uint64(1), uint64(10)).Return([]bridgesync.Bridge{{}}, nil)
mockL2Syncer.On("GetClaims", ctx, uint64(1), uint64(10)).Return([]bridgesync.Claim{{}}, nil)
mockClient.On("GenerateAggchainProof", uint64(1), uint64(10), common.Hash{}).Return(&types.AggchainProof{
Proof: "some-proof", StartBlock: 1, EndBlock: 10}, nil)
mockClient.On("GenerateAggchainProof", uint64(1), uint64(10), common.Hash{}, common.Hash{}, [32]common.Hash{}).Return(&types.AggchainProof{
Proof: []byte("some-proof"), StartBlock: 1, EndBlock: 10}, nil)
},
expectedParams: &types.CertificateBuildParams{
FromBlock: 1,
ToBlock: 10,
RetryCount: 1,
Bridges: []bridgesync.Bridge{{}},
Claims: []bridgesync.Claim{{}},
AggchainProof: "some-proof",
AggchainProof: []byte("some-proof"),
LastSentCertificate: &types.CertificateInfo{
FromBlock: 1,
ToBlock: 10,
Expand All @@ -92,16 +92,16 @@ func Test_AggchainProverFlow_GetCertificateBuildParams(t *testing.T) {
{BlockNum: 5}, {BlockNum: 10}}, nil)
mockL2Syncer.On("GetClaims", ctx, uint64(1), uint64(10)).Return([]bridgesync.Claim{
{BlockNum: 6}, {BlockNum: 9}}, nil)
mockClient.On("GenerateAggchainProof", uint64(1), uint64(10), common.Hash{}).Return(&types.AggchainProof{
Proof: "some-proof", StartBlock: 1, EndBlock: 8}, nil)
mockClient.On("GenerateAggchainProof", uint64(1), uint64(10), common.Hash{}, common.Hash{}, [32]common.Hash{}).Return(&types.AggchainProof{
Proof: []byte("some-proof"), StartBlock: 1, EndBlock: 8}, nil)
},
expectedParams: &types.CertificateBuildParams{
FromBlock: 1,
ToBlock: 8,
RetryCount: 1,
Bridges: []bridgesync.Bridge{{BlockNum: 5}},
Claims: []bridgesync.Claim{{BlockNum: 6}},
AggchainProof: "some-proof",
AggchainProof: []byte("some-proof"),
LastSentCertificate: &types.CertificateInfo{
FromBlock: 1,
ToBlock: 10,
Expand All @@ -118,7 +118,7 @@ func Test_AggchainProverFlow_GetCertificateBuildParams(t *testing.T) {
FromBlock: 1,
ToBlock: 10,
Status: agglayer.InError,
AggchainProof: "existing-proof",
AggchainProof: []byte("existing-proof"),
}, nil)
mockL2Syncer.On("GetBridgesPublished", ctx, uint64(1), uint64(10)).Return([]bridgesync.Bridge{{}}, nil)
mockL2Syncer.On("GetClaims", ctx, uint64(1), uint64(10)).Return([]bridgesync.Claim{{}}, nil)
Expand All @@ -129,12 +129,12 @@ func Test_AggchainProverFlow_GetCertificateBuildParams(t *testing.T) {
RetryCount: 1,
Bridges: []bridgesync.Bridge{{}},
Claims: []bridgesync.Claim{{}},
AggchainProof: "existing-proof",
AggchainProof: []byte("existing-proof"),
LastSentCertificate: &types.CertificateInfo{
FromBlock: 1,
ToBlock: 10,
Status: agglayer.InError,
AggchainProof: "existing-proof",
AggchainProof: []byte("existing-proof"),
},
},
},
Expand All @@ -147,7 +147,7 @@ func Test_AggchainProverFlow_GetCertificateBuildParams(t *testing.T) {
mockL2Syncer.On("GetLastProcessedBlock", ctx).Return(uint64(10), nil)
mockL2Syncer.On("GetBridgesPublished", ctx, uint64(1), uint64(10)).Return([]bridgesync.Bridge{{}}, nil)
mockL2Syncer.On("GetClaims", ctx, uint64(1), uint64(10)).Return([]bridgesync.Claim{{}}, nil)
mockClient.On("GenerateAggchainProof", uint64(1), uint64(10), common.Hash{}).Return(nil, errors.New("some error"))
mockClient.On("GenerateAggchainProof", uint64(1), uint64(10), common.Hash{}, common.Hash{}, [32]common.Hash{}).Return(nil, errors.New("some error"))
},
expectedError: "error fetching aggchain proof for block range 1 : 10 : some error",
},
Expand All @@ -160,8 +160,8 @@ func Test_AggchainProverFlow_GetCertificateBuildParams(t *testing.T) {
mockL2Syncer.On("GetLastProcessedBlock", ctx).Return(uint64(10), nil)
mockL2Syncer.On("GetBridgesPublished", ctx, uint64(6), uint64(10)).Return([]bridgesync.Bridge{{}}, nil)
mockL2Syncer.On("GetClaims", ctx, uint64(6), uint64(10)).Return([]bridgesync.Claim{{}}, nil)
mockClient.On("GenerateAggchainProof", uint64(6), uint64(10), common.Hash{}).Return(&types.AggchainProof{
Proof: "some-proof", StartBlock: 6, EndBlock: 10}, nil)
mockClient.On("GenerateAggchainProof", uint64(6), uint64(10), common.Hash{}, common.Hash{}, [32]common.Hash{}).Return(&types.AggchainProof{
Proof: []byte("some-proof"), StartBlock: 6, EndBlock: 10}, nil)
},
expectedParams: &types.CertificateBuildParams{
FromBlock: 6,
Expand All @@ -170,7 +170,7 @@ func Test_AggchainProverFlow_GetCertificateBuildParams(t *testing.T) {
LastSentCertificate: &types.CertificateInfo{ToBlock: 5},
Bridges: []bridgesync.Bridge{{}},
Claims: []bridgesync.Claim{{}},
AggchainProof: "some-proof",
AggchainProof: []byte("some-proof"),
CreatedAt: uint32(time.Now().UTC().Unix()),
},
},
Expand All @@ -185,8 +185,8 @@ func Test_AggchainProverFlow_GetCertificateBuildParams(t *testing.T) {
{BlockNum: 6}, {BlockNum: 10}}, nil)
mockL2Syncer.On("GetClaims", ctx, uint64(6), uint64(10)).Return([]bridgesync.Claim{
{BlockNum: 8}, {BlockNum: 9}}, nil)
mockClient.On("GenerateAggchainProof", uint64(6), uint64(10), common.Hash{}).Return(&types.AggchainProof{
Proof: "some-proof", StartBlock: 6, EndBlock: 8}, nil)
mockClient.On("GenerateAggchainProof", uint64(6), uint64(10), common.Hash{}, common.Hash{}, [32]common.Hash{}).Return(&types.AggchainProof{
Proof: []byte("some-proof"), StartBlock: 6, EndBlock: 8}, nil)
},
expectedParams: &types.CertificateBuildParams{
FromBlock: 6,
Expand All @@ -195,7 +195,7 @@ func Test_AggchainProverFlow_GetCertificateBuildParams(t *testing.T) {
LastSentCertificate: &types.CertificateInfo{ToBlock: 5},
Bridges: []bridgesync.Bridge{{BlockNum: 6}},
Claims: []bridgesync.Claim{{BlockNum: 8}},
AggchainProof: "some-proof",
AggchainProof: []byte("some-proof"),
CreatedAt: uint32(time.Now().UTC().Unix()),
},
},
Expand Down
33 changes: 26 additions & 7 deletions aggsender/grpc/aggchain_proof_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@ import (
"time"

"github.com/agglayer/aggkit/aggsender/types"
treeTypes "github.com/agglayer/aggkit/tree/types"
"github.com/ethereum/go-ethereum/common"
)

const TIMEOUT = 2

// AggchainProofClientInterface defines an interface for aggchain proof client
type AggchainProofClientInterface interface {
GenerateAggchainProof(startBlock uint64, maxEndBlock uint64, l1infoTreeHash common.Hash) (*types.AggchainProof, error)
GenerateAggchainProof(
startBlock uint64,
maxEndBlock uint64,
l1InfoTreeHash common.Hash,
l1InfoTreeLeaf common.Hash,
l1InfoTreeProof [treeTypes.DefaultHeight]common.Hash,
) (*types.AggchainProof, error)
}

// AggchainProofClient provides an implementation for the AggchainProofClient interface
Expand All @@ -31,22 +38,34 @@ func NewAggchainProofClient(serverAddr string) (*AggchainProofClient, error) {
}, nil
}

func (c *AggchainProofClient) GenerateAggchainProof(startBlock uint64,
maxEndBlock uint64, l1infoTreeHash common.Hash) (*types.AggchainProof, error) {
func (c *AggchainProofClient) GenerateAggchainProof(
startBlock uint64,
maxEndBlock uint64,
l1InfoTreeHash common.Hash,
l1InfoTreeLeaf common.Hash,
l1InfoTreeProof [treeTypes.DefaultHeight]common.Hash,
) (*types.AggchainProof, error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*TIMEOUT)
defer cancel()

convertedProof := make([][]byte, treeTypes.DefaultHeight)
for i := 0; i < int(treeTypes.DefaultHeight); i++ {
convertedProof[i] = l1InfoTreeProof[i].Bytes()
}

resp, err := c.client.GenerateAggchainProof(ctx, &types.GenerateAggchainProofRequest{
StartBlock: startBlock,
MaxEndBlock: maxEndBlock,
L1InfoTreeHash: l1infoTreeHash.Bytes(),
StartBlock: startBlock,
MaxEndBlock: maxEndBlock,
L1InfoTreeHash: l1InfoTreeHash.Bytes(),
L1InfoTreeLeaf: l1InfoTreeLeaf.Bytes(),
L1InfoTreeProof: convertedProof,
})
if err != nil {
return nil, err
}

return &types.AggchainProof{
Proof: string(resp.AggchainProof),
Proof: resp.AggchainProof,
StartBlock: resp.StartBlock,
EndBlock: resp.EndBlock,
}, nil
Expand Down
33 changes: 24 additions & 9 deletions aggsender/grpc/aggchain_proof_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/agglayer/aggkit/aggsender/mocks"
"github.com/agglayer/aggkit/aggsender/types"
treeTypes "github.com/agglayer/aggkit/tree/types"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand All @@ -26,16 +27,23 @@ func TestGenerateAggchainProof_Success(t *testing.T) {
EndBlock: 200,
}

convertedProof := make([][]byte, treeTypes.DefaultHeight)
for i := 0; i < int(treeTypes.DefaultHeight); i++ {
convertedProof[i] = common.Hash{}.Bytes()
}

mockClient.On("GenerateAggchainProof", mock.Anything, &types.GenerateAggchainProofRequest{
StartBlock: 100,
MaxEndBlock: 200,
L1InfoTreeHash: common.Hash{}.Bytes(),
StartBlock: 100,
MaxEndBlock: 200,
L1InfoTreeHash: common.Hash{}.Bytes(),
L1InfoTreeLeaf: common.Hash{}.Bytes(),
L1InfoTreeProof: convertedProof,
}).Return(expectedResponse, nil)

result, err := client.GenerateAggchainProof(100, 200, common.BytesToHash([]byte{}))
result, err := client.GenerateAggchainProof(100, 200, common.Hash{}, common.Hash{}, [32]common.Hash{})

assert.NoError(t, err)
assert.Equal(t, "dummy-proof", result.Proof)
assert.Equal(t, []byte("dummy-proof"), result.Proof)
assert.Equal(t, uint64(100), result.StartBlock)
assert.Equal(t, uint64(200), result.EndBlock)
mockClient.AssertExpectations(t)
Expand All @@ -47,13 +55,20 @@ func TestGenerateAggchainProof_Error(t *testing.T) {

expectedError := errors.New("Generate error")

convertedProof := make([][]byte, treeTypes.DefaultHeight)
for i := 0; i < int(treeTypes.DefaultHeight); i++ {
convertedProof[i] = common.Hash{}.Bytes()
}

mockClient.On("GenerateAggchainProof", mock.Anything, &types.GenerateAggchainProofRequest{
StartBlock: 300,
MaxEndBlock: 400,
L1InfoTreeHash: common.Hash{}.Bytes(),
StartBlock: 300,
MaxEndBlock: 400,
L1InfoTreeHash: common.Hash{}.Bytes(),
L1InfoTreeLeaf: common.Hash{}.Bytes(),
L1InfoTreeProof: convertedProof,
}).Return((*types.GenerateAggchainProofResponse)(nil), expectedError)

result, err := client.GenerateAggchainProof(300, 400, common.Hash{})
result, err := client.GenerateAggchainProof(300, 400, common.Hash{}, common.Hash{}, [32]common.Hash{})

assert.Error(t, err)
assert.Nil(t, result)
Expand Down
32 changes: 17 additions & 15 deletions aggsender/mocks/mock_aggchain_proof_client_interface.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ message GenerateAggchainProofRequest {
uint64 start_block = 1;
// The max end block for which the aggchain proof is requested.
uint64 max_end_block = 2;
// L1 Info tree hash for the nearest finalized block.
bytes l1info_tree_hash = 3;
// L1 Info tree hash.
bytes l1_info_tree_hash = 3;
// L1 Info tree leaf.
bytes l1_info_tree_leaf = 4;
// L1 Info tree proof.
repeated bytes l1_info_tree_proof = 5;
}

// The aggchain proof response message.
Expand Down
Loading

0 comments on commit 8530c98

Please sign in to comment.