Skip to content

Commit

Permalink
develop -> main (#430)
Browse files Browse the repository at this point in the history
* feat: add benchmark tests (#280)

* wip

* config scirpt

* add ga

* improve mt db operations

* lint fixing

* refactor the mt

* dbTx from synchronizer

* reflect suggestions

* feat: separate the service from the bridge controller (#289)

* separate bridge service interface from ctrl

* wip

* fix test

* comments

* small fix

* Feature/#291 smc (#292)

* new smc without genesis

* fix node conf

* genesis + network update

* fix config

* fix accounts

* fix node version

* linter

* Refactor the merkle tree to refactor the last siblings in memory (#294)

* update the sibling

* small updates

* more comments

* remove unnecessary comments

* indexes + migration test utils (#295)

* indexes + migration test utils

* uncomment migration helper

* add migration tests

* sepcify schema

---------

Co-authored-by: Cool Developer <[email protected]>
Co-authored-by: cool-developer <[email protected]>

* fix local l1 bridge address (#300)

* refactor the merkle tree

* Refactor the merkle tree to store the updates in the bulk set (#301)

* bulk insert in merkle  tree

* small fix

* add cache to the service

* update github workflows

* Feature/fork (#310)

* new smc

* update docker images

* linter

* fix e2e

* fix genesis + prover conf

* new genesis and addresses

* genesis fix

* fix node GenBlockNum

* fix proxy event executor

* node version

* mtHeight as constant

* tidy

* support new smc and node fflonk (#315)

* support new smc and node fflonk

* etherman test

* node config

* addresses + node v0.0.3-RC4

* new config values

* revert time increase

---------

Co-authored-by: Cool Developer <[email protected]>

* Merge v0.0.2 (#319)

* Feature/smc fork (#304)

* new smc

* update docker images

* linter

* fix e2e

* fix genesis + prover conf

* new genesis and addresses

* genesis fix

* fix node GenBlockNum

* fix proxy event executor

* node version

* mtHeight as constant

* fix forced batches check (#314)

* fix forced batches check

* fix test

* release workflow (#305)

* Feature/fflonk smc (#316)

* support new smc and node fflonk

* etherman test

* go 1.18

* fix node config

* addresses + node v0.0.3-RC4

* new config values

* increase timeouts

* revert time increase

---------

Co-authored-by: Cool Developer <[email protected]>

---------

Co-authored-by: Cool Developer <[email protected]>

* Bump github.com/grpc-ecosystem/grpc-gateway/v2 from 2.14.0 to 2.15.1 (#320)

Bumps [github.com/grpc-ecosystem/grpc-gateway/v2](https://github.com/grpc-ecosystem/grpc-gateway) from 2.14.0 to 2.15.1.
- [Release notes](https://github.com/grpc-ecosystem/grpc-gateway/releases)
- [Changelog](https://github.com/grpc-ecosystem/grpc-gateway/blob/main/.goreleaser.yml)
- [Commits](grpc-ecosystem/grpc-gateway@v2.14.0...v2.15.1)

---
updated-dependencies:
- dependency-name: github.com/grpc-ecosystem/grpc-gateway/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Pr against develop (#326)

* wip

* add claimtxman

* Fix synchronization when bridge is ahead of the trusted state (#345)

Fix synchronization when bridge is ahead of the trusted state due to a forkID

* fix e2e tests

* add migration tests

* fix duplicate key issue

* Update claimtxman.go

* create claimtx keystore

* update migration sql

* update deposit goroutine

* fix migration

* Feature/#357 rpc (#358)

* sync rpc trusted state + url

* versions

* New event + fix test

* remove broadcast config

* suggestion to avoid duplication in config file

* go mod tidy

* fix tests failures

* Feature/#363 sync (#365)

* remove fatals to handle errors

* log level and refactor

* fix error handling

* Fix/migracion (#368)

* migrations

* fix test

* fix

* fix migrations

* update migrations

* fix invalid nonce

* fix the wrong network ID in the claimtxman

* fix the nonce issue

* Release/v0.0.4 (#385)

* fix retry synchronization after an error (#371)

* fix retry synchronization after an error

* synchronizer test

* create index before delete duplicates (#379)

* create index before delete duplicates

* fix tests

* fix gasprice (#384)

* fix gasprice

* fix e2e tests

* log

* release --clean

---------

Co-authored-by: Cool Developer <[email protected]>

* update versions and go 1.19 (#392)

* update versions and go 1.19

* new conf

* log fix

* reset once in a cycle

* Bump github.com/iden3/go-iden3-crypto from 0.0.14 to 0.0.15 (#402)

Bumps [github.com/iden3/go-iden3-crypto](https://github.com/iden3/go-iden3-crypto) from 0.0.14 to 0.0.15.
- [Release notes](https://github.com/iden3/go-iden3-crypto/releases)
- [Commits](iden3/go-iden3-crypto@v0.0.14...v0.0.15)

---
updated-dependencies:
- dependency-name: github.com/iden3/go-iden3-crypto
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump github.com/lib/pq from 1.10.7 to 1.10.9 (#401)

Bumps [github.com/lib/pq](https://github.com/lib/pq) from 1.10.7 to 1.10.9.
- [Release notes](https://github.com/lib/pq/releases)
- [Commits](lib/pq@v1.10.7...v1.10.9)

---
updated-dependencies:
- dependency-name: github.com/lib/pq
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump github.com/urfave/cli/v2 from 2.25.1 to 2.25.3 (#397)

Bumps [github.com/urfave/cli/v2](https://github.com/urfave/cli) from 2.25.1 to 2.25.3.
- [Release notes](https://github.com/urfave/cli/releases)
- [Changelog](https://github.com/urfave/cli/blob/main/docs/CHANGELOG.md)
- [Commits](urfave/cli@v2.25.1...v2.25.3)

---
updated-dependencies:
- dependency-name: github.com/urfave/cli/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump github.com/hashicorp/golang-lru/v2 from 2.0.1 to 2.0.2 (#395)

Bumps [github.com/hashicorp/golang-lru/v2](https://github.com/hashicorp/golang-lru) from 2.0.1 to 2.0.2.
- [Release notes](https://github.com/hashicorp/golang-lru/releases)
- [Commits](hashicorp/golang-lru@v2.0.1...v2.0.2)

---
updated-dependencies:
- dependency-name: github.com/hashicorp/golang-lru/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* initClaim script (#405)

* initClaim script

* readme

* typo

* Removed the e2e table test as it wasn't being used

* logs (#409)

* logs

* fix log

* fix nonce update (#410)

* Bump golang.org/x/crypto from 0.8.0 to 0.9.0 (#411)

Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.8.0 to 0.9.0.
- [Commits](golang/crypto@v0.8.0...v0.9.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump google.golang.org/grpc from 1.54.0 to 1.55.0 (#407)

Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.54.0 to 1.55.0.
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](grpc/grpc-go@v1.54.0...v1.55.0)

---
updated-dependencies:
- dependency-name: google.golang.org/grpc
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump github.com/0xPolygonHermez/zkevm-node from 0.0.7 to 0.0.8 (#406)

Bumps [github.com/0xPolygonHermez/zkevm-node](https://github.com/0xPolygonHermez/zkevm-node) from 0.0.7 to 0.0.8.
- [Release notes](https://github.com/0xPolygonHermez/zkevm-node/releases)
- [Changelog](https://github.com/0xPolygonHermez/zkevm-node/blob/develop/.goreleaser.yaml)
- [Commits](0xPolygonHermez/zkevm-node@v0.0.7...v0.0.8)

---
updated-dependencies:
- dependency-name: github.com/0xPolygonHermez/zkevm-node
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Alonso Rodriguez <[email protected]>

* Renames references to smart contracts to a more descriptive name

* Update network config defaults

* Require either network section in config or flag

* Make ClaimTxManager optional

* Bump github.com/stretchr/testify from 1.8.2 to 1.8.3

Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.8.2 to 1.8.3.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](stretchr/testify@v1.8.2...v1.8.3)

---
updated-dependencies:
- dependency-name: github.com/stretchr/testify
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

* Enable/Disable the claimtxmanager explicitly

* Enabled autoclaim in the debug config

* Copied versioning system from zkevm-node

* Use the network ID when updating L2 deposits

* Update db/pgstorage/pgstorage.go

Co-authored-by: Alonso Rodriguez <[email protected]>

* Tested upgrade L2 deposit with different rollups

* fix ignore deposit if fails during gasestimation (#424)

* fix ignore deposit if fails during gasestimation

* log

* suggestion

* go.mod go.sum

* mt file and claimtx

* fix (#428)

* fix node config (#429)

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: cool-developer <[email protected]>
Co-authored-by: Cool Developer <[email protected]>
Co-authored-by: Cool Developer <[email protected]>
Co-authored-by: Cool Developer <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Cool Developer <[email protected]>
Co-authored-by: Albert Callarisa <[email protected]>
Co-authored-by: Albert Callarisa <[email protected]>
  • Loading branch information
9 people authored May 26, 2023
1 parent 48adfd4 commit 74b2905
Show file tree
Hide file tree
Showing 87 changed files with 3,569 additions and 2,927 deletions.
1 change: 1 addition & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ updates:
directory: "/"
schedule:
interval: "daily"
target-branch: "develop"
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: 1.18.x
go-version: 1.19.x
- name: Checkout code
uses: actions/checkout@v2
- name: Inject github insteadOf configuration
Expand All @@ -41,7 +41,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: 1.18.x
go-version: 1.19.x
- name: Fork based /ok-to-test checkout
uses: actions/checkout@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.19

- name: Get packr
run: go get -u github.com/gobuffalo/packr/v2/packr2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
strategy:
matrix:
go-version: [ 1.18.x ]
go-version: [ 1.19.x ]
goarch: [ "amd64" ]
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -42,7 +42,7 @@ jobs:
contains(github.event.client_payload.pull_request.head.sha, github.event.client_payload.slash_command.sha)
strategy:
matrix:
go-version: [ 1.18.x ]
go-version: [ 1.19.x ]
goarch: [ "amd64" ]
runs-on: ubuntu-latest
steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-edge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
strategy:
matrix:
go-version: [ 1.18.x ]
go-version: [ 1.19.x ]
goarch: [ "amd64" ]
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -42,7 +42,7 @@ jobs:
contains(github.event.client_payload.pull_request.head.sha, github.event.client_payload.slash_command.sha)
strategy:
matrix:
go-version: [ 1.18.x ]
go-version: [ 1.19.x ]
goarch: [ "amd64" ]
runs-on: ubuntu-latest
steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
strategy:
matrix:
go-version: [ 1.18.x ]
go-version: [ 1.19.x ]
goarch: [ "amd64" ]
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -44,7 +44,7 @@ jobs:
contains(github.event.client_payload.pull_request.head.sha, github.event.client_payload.slash_command.sha)
strategy:
matrix:
go-version: [ 1.18.x ]
go-version: [ 1.19.x ]
goarch: [ "amd64" ]
runs-on: ubuntu-latest
steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/updatedeps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: "1.18.x"
go-version: "1.19.x"
env:
GOARCH: "amd64"
- name: Install Protoc
Expand All @@ -37,5 +37,5 @@ jobs:
title: Update external dependencies
body: Check for new images, test vectors and proto files and update the code to use them.
branch: update-external-dependencies
base: main
base: develop
author: int-bot <[email protected]>
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@
# vendor/
/dist/
.vscode

config/config.mainnet.toml
config/config.testnet.toml
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# CONTAINER FOR BUILDING BINARY
FROM golang:1.18 AS build
FROM golang:1.19 AS build

ENV CGO_ENABLED=0
# INSTALL DEPENDENCIES
Expand Down
20 changes: 11 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include version.mk

DOCKER_COMPOSE := docker-compose -f docker-compose.yml
DOCKER_COMPOSE_STATE_DB := zkevm-state-db
DOCKER_COMPOSE_POOL_DB := zkevm-pool-db
Expand Down Expand Up @@ -26,19 +28,19 @@ STOP_ZKPROVER := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_ZKPROVER) && $(DOCKER_C
STOP_BRIDGE := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_BRIDGE) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_BRIDGE)
STOP := $(DOCKER_COMPOSE) down --remove-orphans

VERSION := $(shell git describe --tags --always)
COMMIT := $(shell git rev-parse --short HEAD)
DATE := $(shell date +%Y-%m-%dT%H:%M:%S%z)
LDFLAGS := -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE)"
LDFLAGS += -X 'github.com/0xPolygonHermez/zkevm-bridge-service.Version=$(VERSION)'
LDFLAGS += -X 'github.com/0xPolygonHermez/zkevm-bridge-service.GitRev=$(GITREV)'
LDFLAGS += -X 'github.com/0xPolygonHermez/zkevm-bridge-service.GitBranch=$(GITBRANCH)'
LDFLAGS += -X 'github.com/0xPolygonHermez/zkevm-bridge-service.BuildDate=$(DATE)'

GO_BASE := $(shell pwd)
GO_BIN := $(GO_BASE)/dist
GO_ENV_VARS := GO_BIN=$(GO_BIN)
GO_BINARY := zkevm-bridge
GO_CMD := $(GO_BASE)/cmd

LINT := $$(go env GOPATH)/bin/golangci-lint run --timeout=5m -E whitespace -E gosec -E gci -E misspell -E gomnd -E gofmt -E goimports -E golint --exclude-use-default=false --max-same-issues 0
BUILD := $(GO_ENV_VARS) go build $(LDFLAGS) -o $(GO_BIN)/$(GO_BINARY) $(GO_CMD)
LINT := $$(go env GOPATH)/bin/golangci-lint run --timeout=5m -E whitespace -E gosec -E gci -E misspell -E gomnd -E gofmt -E goimports --exclude-use-default=false --max-same-issues 0
BUILD := $(GO_ENV_VARS) go build -ldflags "all=$(LDFLAGS)" -o $(GO_BIN)/$(GO_BINARY) $(GO_CMD)

.PHONY: build
build: ## Build the binary locally into ./dist
Expand All @@ -60,7 +62,7 @@ test: ## Runs only short tests without checking race conditions

.PHONY: install-linter
install-linter: ## Installs the linter
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v1.50.1
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v1.51.2

.PHONY: build-docker
build-docker: ## Builds a docker image with the zkevm bridge binary
Expand Down Expand Up @@ -157,7 +159,7 @@ stop-mockserver: ## Stops the mock bridge service
bench: ## benchmark test
$(STOP_BRIDGE_DB) || true
$(RUN_BRIDGE_DB); sleep 3
trap '$(STOP_BRIDGE_DB)' EXIT; go test -run=NOTEST -bench=Small ./test/benchmark/...
trap '$(STOP_BRIDGE_DB)' EXIT; go test -run=NOTEST -timeout=30m -bench=Small ./test/benchmark/...

.PHONY: bench-full
bench-full: export ZKEVM_BRIDGE_DATABASE_PORT = 5432
Expand Down Expand Up @@ -197,4 +199,4 @@ generate-mocks: ## Generates mocks for the tests, using mockery tool
mockery --name=storageInterface --dir=synchronizer --output=synchronizer --outpkg=synchronizer --structname=storageMock --filename=mock_storage.go
mockery --name=bridgectrlInterface --dir=synchronizer --output=synchronizer --outpkg=synchronizer --structname=bridgectrlMock --filename=mock_bridgectrl.go
mockery --name=Tx --srcpkg=github.com/jackc/pgx/v4 --output=synchronizer --outpkg=synchronizer --structname=dbTxMock --filename=mock_dbtx.go
mockery --name=BroadcastServiceClient --srcpkg=github.com/0xPolygonHermez/zkevm-node/sequencer/broadcast/pb --output=synchronizer --outpkg=synchronizer --structname=broadcastMock --filename=mock_broadcast.go
mockery --name=zkEVMClientInterface --dir=synchronizer --output=synchronizer --outpkg=synchronizer --structname=zkEVMClientMock --filename=mock_zkevmclient.go
7 changes: 3 additions & 4 deletions bridgectrl/bridgectrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ func NewBridgeController(cfg Config, networks []uint, mtStore interface{}) (*Bri

for i, network := range networks {
networkIDs[network] = uint8(i)
// onlly add the zero hashes for the first tree to avoid duplication.
mt, err := NewMerkleTree(context.TODO(), mtStore.(merkleTreeStore), cfg.Height, uint8(i), i > 0)
mt, err := NewMerkleTree(context.TODO(), mtStore.(merkleTreeStore), cfg.Height, network)
if err != nil {
return nil, err
}
Expand All @@ -51,13 +50,13 @@ func (bt *BridgeController) getNetworkID(networkID uint) (uint8, error) {
}

// AddDeposit adds deposit information to the bridge tree.
func (bt *BridgeController) AddDeposit(deposit *etherman.Deposit, dbTx pgx.Tx) error {
func (bt *BridgeController) AddDeposit(deposit *etherman.Deposit, depositID uint64, dbTx pgx.Tx) error {
leaf := hashDeposit(deposit)
tID, err := bt.getNetworkID(deposit.NetworkID)
if err != nil {
return err
}
return bt.exitTrees[tID].addLeaf(context.TODO(), leaf, dbTx)
return bt.exitTrees[tID].addLeaf(context.TODO(), depositID, leaf, deposit.DepositCount, dbTx)
}

// ReorgMT reorg the specific merkle tree.
Expand Down
41 changes: 25 additions & 16 deletions bridgectrl/bridgectrl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/0xPolygonHermez/zkevm-bridge-service/db/pgstorage"
"github.com/0xPolygonHermez/zkevm-bridge-service/etherman"
"github.com/0xPolygonHermez/zkevm-bridge-service/test/vectors"
"github.com/0xPolygonHermez/zkevm-bridge-service/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -49,19 +50,19 @@ func TestBridgeTree(t *testing.T) {
store, err := pgstorage.NewPostgresStorage(dbCfg)
require.NoError(t, err)

id, err := store.AddBlock(context.TODO(), &etherman.Block{
BlockNumber: 0,
BlockHash: common.HexToHash("0x29e885edaf8e4b51e1d2e05f9da28161d2fb4f6b1d53827d9b80a23cf2d7d9fc"),
ParentHash: common.Hash{},
}, nil)
require.NoError(t, err)

bt, err := NewBridgeController(cfg, []uint{0, 1000}, store)
require.NoError(t, err)

ctx := context.TODO()
t.Run("Test adding deposit for the bridge tree", func(t *testing.T) {
for i, testVector := range testVectors {
block := &etherman.Block{
BlockNumber: uint64(i + 1),
BlockHash: utils.GenerateRandomHash(),
ParentHash: common.Hash{},
}
blockID, err := store.AddBlock(context.TODO(), block, nil)
require.NoError(t, err)
amount, _ := new(big.Int).SetString(testVector.Amount, 0)
deposit := &etherman.Deposit{
LeafType: 0,
Expand All @@ -70,24 +71,31 @@ func TestBridgeTree(t *testing.T) {
Amount: amount,
DestinationNetwork: testVector.DestinationNetwork,
DestinationAddress: common.HexToAddress(testVector.DestinationAddress),
BlockNumber: 0,
BlockID: blockID,
DepositCount: uint(i),
Metadata: common.FromHex(testVector.Metadata),
}
leafHash := hashDeposit(deposit)
assert.Equal(t, testVector.ExpectedHash, hex.EncodeToString(leafHash[:]))

err = bt.AddDeposit(deposit, nil)
depositID, err := store.AddDeposit(ctx, deposit, nil)
require.NoError(t, err)
err = bt.AddDeposit(deposit, depositID, nil)
require.NoError(t, err)

// test reorg
orgRoot, err := bt.exitTrees[0].store.GetRoot(ctx, uint(i+1), 0, nil)
orgRoot, err := bt.exitTrees[0].store.GetRoot(ctx, uint(i), 0, nil)
require.NoError(t, err)
require.NoError(t, store.Reset(ctx, uint64(i), deposit.NetworkID, nil))
err = bt.ReorgMT(uint(i), testVectors[i].OriginalNetwork, nil)
require.NoError(t, err)
err = bt.AddDeposit(deposit, nil)
blockID, err = store.AddBlock(context.TODO(), block, nil)
require.NoError(t, err)
deposit.BlockID = blockID
depositID, err = store.AddDeposit(ctx, deposit, nil)
require.NoError(t, err)
err = bt.AddDeposit(deposit, depositID, nil)
require.NoError(t, err)
newRoot, err := bt.exitTrees[0].store.GetRoot(ctx, uint(i+1), 0, nil)
newRoot, err := bt.exitTrees[0].store.GetRoot(ctx, uint(i), 0, nil)
require.NoError(t, err)
assert.Equal(t, orgRoot, newRoot)

Expand All @@ -101,16 +109,17 @@ func TestBridgeTree(t *testing.T) {
BlockNumber: uint64(i + 1),
GlobalExitRoot: Hash(common.BytesToHash(roots[0]), common.BytesToHash(roots[1])),
ExitRoots: []common.Hash{common.BytesToHash(roots[0]), common.BytesToHash(roots[1])},
BlockID: id,
BlockID: blockID,
}, nil)
require.NoError(t, err)

err = store.AddTrustedGlobalExitRoot(context.TODO(), &etherman.GlobalExitRoot{
isUpdated, err := store.AddTrustedGlobalExitRoot(context.TODO(), &etherman.GlobalExitRoot{
BlockNumber: 0,
GlobalExitRoot: Hash(common.BytesToHash(roots[0]), common.BytesToHash(roots[1])),
ExitRoots: []common.Hash{common.BytesToHash(roots[0]), common.BytesToHash(roots[1])},
BlockID: id,
BlockID: blockID,
}, nil)
require.True(t, isUpdated)
require.NoError(t, err)
}
})
Expand Down
9 changes: 4 additions & 5 deletions bridgectrl/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import (
// merkleTreeStore interface for the Merkle Tree
type merkleTreeStore interface {
Get(ctx context.Context, key []byte, dbTx pgx.Tx) ([][]byte, error)
Set(ctx context.Context, key []byte, value [][]byte, rootID uint64, dbTx pgx.Tx) error
ResetMT(ctx context.Context, depositCount uint, network uint8, dbTx pgx.Tx) error
GetRoot(ctx context.Context, depositCount uint, network uint8, dbTx pgx.Tx) ([]byte, error)
SetRoot(ctx context.Context, root []byte, depositCount uint, network uint8, dbTx pgx.Tx) (uint64, error)
GetLastDepositCount(ctx context.Context, network uint8, dbTx pgx.Tx) (uint, error)
BulkSet(ctx context.Context, rows [][]interface{}, dbTx pgx.Tx) error
GetRoot(ctx context.Context, depositCount uint, network uint, dbTx pgx.Tx) ([]byte, error)
SetRoot(ctx context.Context, root []byte, depositID uint64, depositCount uint, network uint, dbTx pgx.Tx) error
GetLastDepositCount(ctx context.Context, network uint, dbTx pgx.Tx) (uint, error)
}
Loading

0 comments on commit 74b2905

Please sign in to comment.