Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

Custom EthTxManager on agglayer #109

Merged
merged 8 commits into from
Apr 5, 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
18 changes: 15 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ LDFLAGS += -X 'github.com/0xPolygon/agglayer.GitRev=$(GITREV)'
LDFLAGS += -X 'github.com/0xPolygon/agglayer.GitBranch=$(GITBRANCH)'
LDFLAGS += -X 'github.com/0xPolygon/agglayer.BuildDate=$(DATE)'

DOCKERCOMPOSE := docker-compose -f docker/docker-compose.yaml
DOCKERCOMPOSESTATEDB := agglayer-db

RUNSTATEDB := $(DOCKERCOMPOSE) up -d $(DOCKERCOMPOSESTATEDB)
STOP := $(DOCKERCOMPOSE) down --remove-orphans

.PHONY: build
build: ## Builds the binary locally into ./dist
$(GOENVVARS) go build -ldflags "all=$(LDFLAGS)" -o $(GOBIN)/$(GOBINARY) $(GOCMD)
Expand Down Expand Up @@ -111,13 +117,19 @@ help: ## Prints the help
| awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.PHONY: e2e-tests
e2e-tests: ## Runs E2E tests
e2e-tests: stop ## Runs E2E tests
go test -v -timeout=30m github.com/0xPolygon/agglayer/test

.PHONY: unit-tests
unit-tests: ## Runs unit tests
go test -v -timeout=5m -race -shuffle=on -coverprofile coverage.out `go list ./... | grep -v test`
unit-tests: stop ## Runs unit tests
$(RUNSTATEDB)
sleep 40
trap '$(STOP)' EXIT; MallocNanoZone=0 go test -v -timeout=5m -race -shuffle=on -coverprofile coverage.out `go list ./... | grep -v test`

.PHONY: generate-mocks
generate-mocks: ## Generates mocks and other autogenerated types
mockery

.PHONY: stop
stop: ## Stops all services
$(STOP)
6 changes: 3 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

jRPC "github.com/0xPolygon/cdk-rpc/rpc"
dbConf "github.com/0xPolygonHermez/zkevm-node/db"
"github.com/0xPolygonHermez/zkevm-node/ethtxmanager"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
Expand All @@ -35,6 +34,7 @@ import (
"github.com/0xPolygon/agglayer/log"
"github.com/0xPolygon/agglayer/network"
"github.com/0xPolygon/agglayer/rpc"
"github.com/0xPolygon/agglayer/txmanager"
)

const appName = "cdk-agglayer"
Expand Down Expand Up @@ -131,11 +131,11 @@ func start(cliCtx *cli.Context) error {
}

// Prepare EthTxMan client
ethTxManagerStorage, err := ethtxmanager.NewPostgresStorage(c.DB)
ethTxManagerStorage, err := txmanager.NewPostgresStorage(c.DB)
if err != nil {
return err
}
etm := ethtxmanager.New(c.EthTxManager.Config, &ethMan, ethTxManagerStorage, &ethMan)
etm := txmanager.New(c.EthTxManager, &ethMan, ethTxManagerStorage, &ethMan)

// Create opentelemetry metric provider
meterProvider, err := createMeterProvider()
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type EthTxManagerConfig struct {
GasOffset uint64 `mapstructure:"GasOffset"`
KMSKeyName string `mapstructure:"KMSKeyName"`
KMSConnectionTimeout types.Duration `mapstructure:"KMSConnectionTimeout"`
MaxRetries uint64 `mapstructure:"MaxRetries"`
}

// Load loads the configuration baseed on the cli context
Expand Down
1 change: 1 addition & 0 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const DefaultValues = `
KMSKeyName = "gcp/resource/id"
KMSConnectionTimeout = "30s"
GasOffset = 100000
MaxRetries = 10

[L1]
ChainID = 1337
Expand Down
6 changes: 6 additions & 0 deletions db/migrations/0002.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- +migrate Up
goran-ethernal marked this conversation as resolved.
Show resolved Hide resolved
ALTER TABLE state.monitored_txs
ADD COLUMN num_retries DECIMAL(78, 0) NOT NULL DEFAULT 0;

-- +migrate Down
ALTER TABLE state.monitored_txs DROP COLUMN num_retries;
1 change: 1 addition & 0 deletions docker/data/agglayer/agglayer.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
GasOffset = 100000
KMSKeyName = ""
KMSConnectionTimeout = "30s"
MaxRetries = 10

[L1]
ChainID = 1337
Expand Down
2 changes: 1 addition & 1 deletion interop/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (e *Executor) Execute(ctx context.Context, signedTx tx.SignedTx) error {

if batch.StateRoot != signedTx.Tx.ZKP.NewStateRoot || batch.LocalExitRoot != signedTx.Tx.ZKP.NewLocalExitRoot {
return fmt.Errorf(
"Mismatch detected, expected local exit root: %s actual: %s. expected state root: %s actual: %s",
"mismatch detected, expected local exit root: %s actual: %s. expected state root: %s actual: %s",
signedTx.Tx.ZKP.NewLocalExitRoot.Hex(),
batch.LocalExitRoot.Hex(),
signedTx.Tx.ZKP.NewStateRoot.Hex(),
Expand Down
10 changes: 5 additions & 5 deletions interop/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"testing"

"github.com/0xPolygon/agglayer/log"
txmTypes "github.com/0xPolygon/agglayer/txmanager/types"
jRPC "github.com/0xPolygon/cdk-rpc/rpc"
"github.com/0xPolygonHermez/zkevm-node/ethtxmanager"
rpctypes "github.com/0xPolygonHermez/zkevm-node/jsonrpc/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -313,9 +313,9 @@ func TestExecutor_GetTxStatus(t *testing.T) {
expectedError := jRPC.NewRPCError(rpctypes.DefaultErrorCode, "failed to get tx, error: sampleError")

ethTxManager.On("Result", mock.Anything, ethTxManOwner, hash.Hex(), dbTx).
Return(ethtxmanager.MonitoredTxResult{
Return(txmTypes.MonitoredTxResult{
ID: "0x1",
Status: ethtxmanager.MonitoredTxStatus("0x1"),
Status: txmTypes.MonitoredTxStatus("0x1"),
}, nil).Once()

result, err := executor.GetTxStatus(context.Background(), hash, dbTx)
Expand All @@ -324,9 +324,9 @@ func TestExecutor_GetTxStatus(t *testing.T) {
assert.NoError(t, err)

ethTxManager.On("Result", mock.Anything, ethTxManOwner, hash.Hex(), dbTx).
Return(ethtxmanager.MonitoredTxResult{
Return(txmTypes.MonitoredTxResult{
ID: "0x0",
Status: ethtxmanager.MonitoredTxStatus("0x1"),
Status: txmTypes.MonitoredTxStatus("0x1"),
}, errors.New("sampleError")).Once()

result, err = executor.GetTxStatus(context.Background(), hash, dbTx)
Expand Down
117 changes: 10 additions & 107 deletions mocks/eth_tx_manager.generated.go

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

Loading
Loading