Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add synchronization for banana sequences #118

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
4 changes: 2 additions & 2 deletions synchronizer/batches.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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],
})
}
Expand Down
14 changes: 14 additions & 0 deletions synchronizer/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 (
Expand All @@ -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))
}
Expand All @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions synchronizer/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Loading