From bc61672df580c954b0ca516ff7eaeaa0d9b45d81 Mon Sep 17 00:00:00 2001 From: Joan Esteban <129153821+joanestebanr@users.noreply.github.com> Date: Fri, 13 Sep 2024 16:56:05 +0200 Subject: [PATCH] Add synchronization for banana sequences (#118) --- go.mod | 2 +- go.sum | 2 ++ synchronizer/batches.go | 4 ++-- synchronizer/util.go | 14 ++++++++++++++ synchronizer/util_test.go | 2 ++ 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 7ed9e877..7e9f2a30 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/0xPolygon/cdk-data-availability go 1.21.3 require ( - github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240426091844-5cd6921eed9f + github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240826154954-f6182d2b17a2 github.com/DATA-DOG/go-sqlmock v1.5.1 github.com/didip/tollbooth/v6 v6.1.2 github.com/ethereum/go-ethereum v1.13.14 diff --git a/go.sum b/go.sum index 61e7b3e4..78062e26 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240426091844-5cd6921eed9f h1:EiChBxSyJxMjgPdbYWujqD32r991Yhffrm78STAXB4k= github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240426091844-5cd6921eed9f/go.mod h1:mFlcEjsm2YBBsu8atHJ3zyVnwM+Z/fMXpVmIJge+WVU= +github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240826154954-f6182d2b17a2 h1:N5qvWG4amhUt6d1F4Kf8AdJZs4z7/xZfE3v/Im2afNM= +github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240826154954-f6182d2b17a2/go.mod h1:mFlcEjsm2YBBsu8atHJ3zyVnwM+Z/fMXpVmIJge+WVU= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= github.com/DATA-DOG/go-sqlmock v1.5.1 h1:FK6RCIUSfmbnI/imIICmboyQBkOckutaa6R5YYlLZyo= diff --git a/synchronizer/batches.go b/synchronizer/batches.go index c313ed8d..85e17388 100644 --- a/synchronizer/batches.go +++ b/synchronizer/batches.go @@ -228,7 +228,7 @@ func (bs *BatchSynchronizer) filterEvents(ctx context.Context) error { // Handle events for _, event := range events { if err = bs.handleEvent(ctx, event); err != nil { - log.Errorf("failed to handle event: %v", err) + log.Errorf("failed to handleEvent: %v", err) return setStartBlock(ctx, bs.db, event.Raw.BlockNumber-1, L1SyncTask) } } @@ -258,7 +258,7 @@ func (bs *BatchSynchronizer) handleEvent( var batchKeys []types.BatchKey for i, j := 0, len(keys)-1; i < len(keys); i, j = i+1, j-1 { batchKeys = append(batchKeys, types.BatchKey{ - Number: event.NumBatch - uint64(i), + Number: event.NumBatch - uint64(i), //nolint:gosec Hash: keys[j], }) } diff --git a/synchronizer/util.go b/synchronizer/util.go index 9d394219..b389b6b8 100644 --- a/synchronizer/util.go +++ b/synchronizer/util.go @@ -7,8 +7,10 @@ import ( "fmt" "strings" + bananaValidium "github.com/0xPolygon/cdk-contracts-tooling/contracts/banana/polygonvalidiumetrog" elderberryValidium "github.com/0xPolygon/cdk-contracts-tooling/contracts/elderberry/polygonvalidiumetrog" etrogValidium "github.com/0xPolygon/cdk-contracts-tooling/contracts/etrog/polygonvalidiumetrog" + "github.com/0xPolygon/cdk-data-availability/log" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" @@ -24,6 +26,10 @@ var ( methodIDSequenceBatchesValidiumElderberry = crypto.Keccak256( []byte("sequenceBatchesValidium((bytes32,bytes32,uint64,bytes32)[],uint64,uint64,address,bytes)"), )[:methodIDLen] + // methodIDSequenceBatchesValidiumBanana is sequenceBatchesValidium method id in Banana fork (0x165e8a8d) + methodIDSequenceBatchesValidiumBanana = crypto.Keccak256( + []byte("sequenceBatchesValidium((bytes32,bytes32,uint64,bytes32)[],uint32,uint64,bytes32,address,bytes)"), + )[:methodIDLen] ) const ( @@ -50,6 +56,11 @@ func UnpackTxData(txData []byte) ([]common.Hash, error) { if err != nil { return nil, err } + } else if bytes.Equal(methodID, methodIDSequenceBatchesValidiumBanana) { + a, err = abi.JSON(strings.NewReader(bananaValidium.PolygonvalidiumetrogMetaData.ABI)) + if err != nil { + return nil, err + } } else { return nil, fmt.Errorf("unrecognized method id: %s", hex.EncodeToString(methodID)) } @@ -61,16 +72,19 @@ func UnpackTxData(txData []byte) ([]common.Hash, error) { data, err := method.Inputs.Unpack(txData[methodIDLen:]) if err != nil { + log.Errorf("error Unpack data: %v", err) return nil, err } bytes, err := json.Marshal(data[0]) if err != nil { + log.Errorf("error marshalling data: %v", err) return nil, err } var batches []etrogValidium.PolygonValidiumEtrogValidiumBatchData if err = json.Unmarshal(bytes, &batches); err != nil { + log.Errorf("error Unmarshal data: %v", err) return nil, err } diff --git a/synchronizer/util_test.go b/synchronizer/util_test.go index 4c2b12fc..741cb44c 100644 --- a/synchronizer/util_test.go +++ b/synchronizer/util_test.go @@ -11,8 +11,10 @@ func Test_SequenceBatchesValidiumMethodIDs_Equality(t *testing.T) { var ( expectedSequenceBatchesValidiumEtrog = "2d72c248" expectedSequenceBatchesValidiumElderberry = "db5b0ed7" + expectedSequenceBatchesValidiumBanana = "165e8a8d" ) require.Equal(t, expectedSequenceBatchesValidiumEtrog, hex.EncodeToString(methodIDSequenceBatchesValidiumEtrog)) require.Equal(t, expectedSequenceBatchesValidiumElderberry, hex.EncodeToString(methodIDSequenceBatchesValidiumElderberry)) + require.Equal(t, expectedSequenceBatchesValidiumBanana, hex.EncodeToString(methodIDSequenceBatchesValidiumBanana)) }