Skip to content

Commit

Permalink
Ethtx Manager as a library (#9)
Browse files Browse the repository at this point in the history
* wip

* test

* remove GHA

* add l1 confirmation blocks

* update readme

* update readme
  • Loading branch information
ToniRamirezM authored Jan 23, 2024
1 parent 509a587 commit bb336b7
Show file tree
Hide file tree
Showing 97 changed files with 415 additions and 44,882 deletions.
32 changes: 0 additions & 32 deletions .github/workflows/push-docker-develop.yml

This file was deleted.

33 changes: 0 additions & 33 deletions .github/workflows/push-docker-tagged.yml

This file was deleted.

61 changes: 0 additions & 61 deletions .github/workflows/release.yml

This file was deleted.

33 changes: 0 additions & 33 deletions .github/workflows/test.yml

This file was deleted.

4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/dist/

/test/*.bin

**/.DS_Store
.vscode
.idea/
Expand Down
32 changes: 0 additions & 32 deletions .golangci.yml

This file was deleted.

22 changes: 0 additions & 22 deletions .goreleaser.yaml

This file was deleted.

20 changes: 0 additions & 20 deletions Dockerfile

This file was deleted.

43 changes: 0 additions & 43 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
include version.mk

ARCH := $(shell arch)

ifeq ($(ARCH),x86_64)
Expand All @@ -15,27 +13,12 @@ GOENVVARS := GOBIN=$(GOBIN) CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH)
GOBINARY := zkevm-ethtx-manager
GOCMD := $(GOBASE)/cmd

LDFLAGS += -X 'github.com/0xPolygonHermez/zkevm-ethtx-manager.Version=$(VERSION)'
LDFLAGS += -X 'github.com/0xPolygonHermez/zkevm-ethtx-manager=$(GITREV)'
LDFLAGS += -X 'github.com/0xPolygonHermez/zkevm-ethtx-manager=$(GITBRANCH)'
LDFLAGS += -X 'github.com/0xPolygonHermez/zkevm-ethtx-manager=$(DATE)'

# Check dependencies
# Check for Go
.PHONY: check-go
check-go:
@which go > /dev/null || (echo "Error: Go is not installed" && exit 1)

# Check for Docker
.PHONY: check-docker
check-docker:
@which docker > /dev/null || (echo "Error: docker is not installed" && exit 1)

# Check for Docker-compose
.PHONY: check-docker-compose
check-docker-compose:
@which docker-compose > /dev/null || (echo "Error: docker-compose is not installed" && exit 1)

# Check for Curl
.PHONY: check-curl
check-curl:
Expand All @@ -44,34 +27,8 @@ check-curl:
# Targets that require the checks
build: check-go
lint: check-go
build-docker: check-docker
build-docker-nc: check-docker
run: check-docker check-docker-compose
stop: check-docker check-docker-compose
install-linter: check-go check-curl

.PHONY: build
build: ## Builds the binary locally into ./dist
$(GOENVVARS) go build -ldflags "all=$(LDFLAGS)" -o $(GOBIN)/$(GOBINARY) $(GOCMD)

.PHONY: build-docker
build-docker: ## Builds a docker image with the binary
docker build -t zkevm-ethtx-manager -f ./Dockerfile .

.PHONY: build-docker-nc
build-docker-nc: ## Builds a docker image with the binary - but without build cache
docker build --no-cache=true -t zkevm-ethtx-manager -f ./Dockerfile .

.PHONY: run-ethtxmanager
run: ## Runs the eth tx manager
docker-compose up -d zkevm-ethtx-manager-db
sleep 2
docker-compose up -d zkevm-ethtx-manager

.PHONY: stop
stop: ## Stops all services
docker-compose down

.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.54.2
Expand Down
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,38 @@
# zkevm-ethtx-manager
zkevm-ethtx-manager
Stateless manager to sent transactions to L1.

## Main Funtions
### Add Transaction
`func (c *Client) Add(ctx context.Context, to *common.Address, forcedNonce *uint64, value *big.Int, data []byte) (common.Hash, error)`

Adds a transaction to be sent to L1. The returned hash is calculated over the *to*, *nonce*, *value* and *data* fields.

Parameter forcedNonce is optional, if nil is passed the current nonce is obtained from the L1 node.

### Get Transaction Status
`func (c *Client) Result(ctx context.Context, id common.Hash) (MonitoredTxResult, error)`

Result returns the current result of the transaction execution with all the details.

### Get All Transactions Status
`func (c *Client) ResultsByStatus(ctx context.Context, statuses []MonitoredTxStatus) ([]MonitoredTxResult, error)`

ResultsByStatus returns all the results for all the monitored txs matching the provided statuses.
If the statuses are empty, all the statuses are considered.

### Pending L1 Transactions
`func (c *Client) PendingL1Txs(ctx context.Context) (bool, error)`

Returns whether there are pending transactions to be mined in L1.

### Transactions statuses

- **Created**: the tx was just added to the volatile storage
- **Sent**: transaction was sent to L1
- **Failed**: the tx was already mined and failed with an error that can't be recovered automatically, ex: the data in the tx is invalid and the tx gets reverted
- **Confirmed**: the tx was already mined and the receipt status is Successful. Confirmation waits for the configured number of blocks to be considered final.

#### Legacy statuses

- **Reorged**: is used when a monitored tx was already confirmed but the L1 block where this tx was confirmed has been reorged, in this situation the caller needs to review this information and wait until it gets confirmed again in a future block.
- **Done**: the tx was set by the owner as done
Loading

0 comments on commit bb336b7

Please sign in to comment.