Skip to content

Commit bc61672

Browse files
authored
Add synchronization for banana sequences (#118)
1 parent d7ed6fd commit bc61672

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/0xPolygon/cdk-data-availability
33
go 1.21.3
44

55
require (
6-
github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240426091844-5cd6921eed9f
6+
github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240826154954-f6182d2b17a2
77
github.com/DATA-DOG/go-sqlmock v1.5.1
88
github.com/didip/tollbooth/v6 v6.1.2
99
github.com/ethereum/go-ethereum v1.13.14

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240426091844-5cd6921eed9f h1:EiChBxSyJxMjgPdbYWujqD32r991Yhffrm78STAXB4k=
22
github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240426091844-5cd6921eed9f/go.mod h1:mFlcEjsm2YBBsu8atHJ3zyVnwM+Z/fMXpVmIJge+WVU=
3+
github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240826154954-f6182d2b17a2 h1:N5qvWG4amhUt6d1F4Kf8AdJZs4z7/xZfE3v/Im2afNM=
4+
github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240826154954-f6182d2b17a2/go.mod h1:mFlcEjsm2YBBsu8atHJ3zyVnwM+Z/fMXpVmIJge+WVU=
35
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8=
46
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
57
github.com/DATA-DOG/go-sqlmock v1.5.1 h1:FK6RCIUSfmbnI/imIICmboyQBkOckutaa6R5YYlLZyo=

synchronizer/batches.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func (bs *BatchSynchronizer) filterEvents(ctx context.Context) error {
228228
// Handle events
229229
for _, event := range events {
230230
if err = bs.handleEvent(ctx, event); err != nil {
231-
log.Errorf("failed to handle event: %v", err)
231+
log.Errorf("failed to handleEvent: %v", err)
232232
return setStartBlock(ctx, bs.db, event.Raw.BlockNumber-1, L1SyncTask)
233233
}
234234
}
@@ -258,7 +258,7 @@ func (bs *BatchSynchronizer) handleEvent(
258258
var batchKeys []types.BatchKey
259259
for i, j := 0, len(keys)-1; i < len(keys); i, j = i+1, j-1 {
260260
batchKeys = append(batchKeys, types.BatchKey{
261-
Number: event.NumBatch - uint64(i),
261+
Number: event.NumBatch - uint64(i), //nolint:gosec
262262
Hash: keys[j],
263263
})
264264
}

synchronizer/util.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import (
77
"fmt"
88
"strings"
99

10+
bananaValidium "github.com/0xPolygon/cdk-contracts-tooling/contracts/banana/polygonvalidiumetrog"
1011
elderberryValidium "github.com/0xPolygon/cdk-contracts-tooling/contracts/elderberry/polygonvalidiumetrog"
1112
etrogValidium "github.com/0xPolygon/cdk-contracts-tooling/contracts/etrog/polygonvalidiumetrog"
13+
"github.com/0xPolygon/cdk-data-availability/log"
1214
"github.com/ethereum/go-ethereum/accounts/abi"
1315
"github.com/ethereum/go-ethereum/common"
1416
"github.com/ethereum/go-ethereum/crypto"
@@ -24,6 +26,10 @@ var (
2426
methodIDSequenceBatchesValidiumElderberry = crypto.Keccak256(
2527
[]byte("sequenceBatchesValidium((bytes32,bytes32,uint64,bytes32)[],uint64,uint64,address,bytes)"),
2628
)[:methodIDLen]
29+
// methodIDSequenceBatchesValidiumBanana is sequenceBatchesValidium method id in Banana fork (0x165e8a8d)
30+
methodIDSequenceBatchesValidiumBanana = crypto.Keccak256(
31+
[]byte("sequenceBatchesValidium((bytes32,bytes32,uint64,bytes32)[],uint32,uint64,bytes32,address,bytes)"),
32+
)[:methodIDLen]
2733
)
2834

2935
const (
@@ -50,6 +56,11 @@ func UnpackTxData(txData []byte) ([]common.Hash, error) {
5056
if err != nil {
5157
return nil, err
5258
}
59+
} else if bytes.Equal(methodID, methodIDSequenceBatchesValidiumBanana) {
60+
a, err = abi.JSON(strings.NewReader(bananaValidium.PolygonvalidiumetrogMetaData.ABI))
61+
if err != nil {
62+
return nil, err
63+
}
5364
} else {
5465
return nil, fmt.Errorf("unrecognized method id: %s", hex.EncodeToString(methodID))
5566
}
@@ -61,16 +72,19 @@ func UnpackTxData(txData []byte) ([]common.Hash, error) {
6172

6273
data, err := method.Inputs.Unpack(txData[methodIDLen:])
6374
if err != nil {
75+
log.Errorf("error Unpack data: %v", err)
6476
return nil, err
6577
}
6678

6779
bytes, err := json.Marshal(data[0])
6880
if err != nil {
81+
log.Errorf("error marshalling data: %v", err)
6982
return nil, err
7083
}
7184

7285
var batches []etrogValidium.PolygonValidiumEtrogValidiumBatchData
7386
if err = json.Unmarshal(bytes, &batches); err != nil {
87+
log.Errorf("error Unmarshal data: %v", err)
7488
return nil, err
7589
}
7690

synchronizer/util_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ func Test_SequenceBatchesValidiumMethodIDs_Equality(t *testing.T) {
1111
var (
1212
expectedSequenceBatchesValidiumEtrog = "2d72c248"
1313
expectedSequenceBatchesValidiumElderberry = "db5b0ed7"
14+
expectedSequenceBatchesValidiumBanana = "165e8a8d"
1415
)
1516

1617
require.Equal(t, expectedSequenceBatchesValidiumEtrog, hex.EncodeToString(methodIDSequenceBatchesValidiumEtrog))
1718
require.Equal(t, expectedSequenceBatchesValidiumElderberry, hex.EncodeToString(methodIDSequenceBatchesValidiumElderberry))
19+
require.Equal(t, expectedSequenceBatchesValidiumBanana, hex.EncodeToString(methodIDSequenceBatchesValidiumBanana))
1820
}

0 commit comments

Comments
 (0)