mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 11:26:44 +01:00
Compare commits
7 Commits
feature/fa
...
hardcoded-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
714530e164 | ||
|
|
378ba669b6 | ||
|
|
f07fd82822 | ||
|
|
3865c0a9eb | ||
|
|
d465d51e78 | ||
|
|
e23d0a07d2 | ||
|
|
88b17cbe99 |
29
.github/workflows/release.yml
vendored
Normal file
29
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
name: goreleaser
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
jobs:
|
||||
goreleaser:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
-
|
||||
name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.16
|
||||
-
|
||||
name: Run GoReleaser
|
||||
uses: goreleaser/goreleaser-action@v2
|
||||
with:
|
||||
version: latest
|
||||
args: release --rm-dist
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
36
.goreleaser.yml
Normal file
36
.goreleaser.yml
Normal file
@@ -0,0 +1,36 @@
|
||||
before:
|
||||
hooks:
|
||||
- go mod download
|
||||
|
||||
builds:
|
||||
- main: ./cli/node/main.go
|
||||
binary: node
|
||||
id: node
|
||||
goos:
|
||||
- linux
|
||||
- darwin
|
||||
- windows
|
||||
hooks:
|
||||
pre: make migration-pack
|
||||
post: make migration-clean
|
||||
|
||||
archives:
|
||||
- replacements:
|
||||
darwin: Darwin
|
||||
linux: Linux
|
||||
windows: Windows
|
||||
386: i386
|
||||
amd64: x86_64
|
||||
|
||||
checksum:
|
||||
name_template: 'checksums.txt'
|
||||
|
||||
snapshot:
|
||||
name_template: "{{ .Tag }}-next"
|
||||
|
||||
changelog:
|
||||
sort: asc
|
||||
filters:
|
||||
exclude:
|
||||
- '^docs:'
|
||||
- '^test:'
|
||||
12
Makefile
12
Makefile
@@ -3,8 +3,8 @@
|
||||
# Project variables.
|
||||
PACKAGE := github.com/hermeznetwork/hermez-node
|
||||
VERSION := $(shell git describe --tags --always)
|
||||
BUILD := $(shell git rev-parse --short HEAD)
|
||||
BUILD_DATE := $(shell date +%Y-%m-%dT%H:%M:%S%z)
|
||||
COMMIT := $(shell git rev-parse --short HEAD)
|
||||
DATE := $(shell date +%Y-%m-%dT%H:%M:%S%z)
|
||||
PROJECT_NAME := $(shell basename "$(PWD)")
|
||||
|
||||
# Go related variables.
|
||||
@@ -23,7 +23,7 @@ CONFIG ?= $(GOBASE)/cli/node/cfg.buidler.toml
|
||||
POSTGRES_PASS ?= yourpasswordhere
|
||||
|
||||
# Use linker flags to provide version/build settings.
|
||||
LDFLAGS=-ldflags "-X=main.Version=$(VERSION) -X=main.Build=$(BUILD) -X=main.Date=$(BUILD_DATE)"
|
||||
LDFLAGS=-ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE)"
|
||||
|
||||
# PID file will keep the process id of the server.
|
||||
PID_PROOF_MOCK := /tmp/.$(PROJECT_NAME).proof.pid
|
||||
@@ -94,11 +94,11 @@ install:
|
||||
@echo " > Checking if there is any missing dependencies..."
|
||||
$(GOENVVARS) go get $(GOCMD)/... $(get)
|
||||
|
||||
## run: Run Hermez node.
|
||||
run:
|
||||
## run-node: Run Hermez node.
|
||||
run-node:
|
||||
@bash -c "$(MAKE) clean build"
|
||||
@echo " > Running $(PROJECT_NAME)"
|
||||
@$(GOBIN)/$(GOBINARY) --mode $(MODE) --cfg $(CONFIG) run
|
||||
@$(GOBIN)/$(GOBINARY) run --mode $(MODE) --cfg $(CONFIG)
|
||||
|
||||
## run-proof-mock: Run proof server mock API.
|
||||
run-proof-mock: stop-proof-mock
|
||||
|
||||
@@ -25,13 +25,13 @@ there are more information about the config file into [cli/node/README.md](cli/n
|
||||
After setting the config, you can build and run the Hermez Node as a synchronizer:
|
||||
|
||||
```shell
|
||||
$ make run
|
||||
$ make run-node
|
||||
```
|
||||
|
||||
Or build and run as a coordinator, and also passing the config file from other location:
|
||||
|
||||
```shell
|
||||
$ MODE=sync CONFIG=cli/node/cfg.buidler.toml make run
|
||||
$ MODE=sync CONFIG=cli/node/cfg.buidler.toml make run-node
|
||||
```
|
||||
|
||||
To check the useful make commands:
|
||||
|
||||
@@ -522,11 +522,16 @@ func TestMain(m *testing.M) {
|
||||
WithdrawalDelay: uint64(3000),
|
||||
}
|
||||
|
||||
stateAPIUpdater = stateapiupdater.NewUpdater(hdb, nodeConfig, &common.SCVariables{
|
||||
stateAPIUpdater, err = stateapiupdater.NewUpdater(hdb, nodeConfig, &common.SCVariables{
|
||||
Rollup: rollupVars,
|
||||
Auction: auctionVars,
|
||||
WDelayer: wdelayerVars,
|
||||
}, constants)
|
||||
}, constants, &stateapiupdater.RecommendedFeePolicy{
|
||||
PolicyType: stateapiupdater.RecommendedFeePolicyTypeAvgLastHour,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Generate test data, as expected to be received/sended from/to the API
|
||||
testCoords := genTestCoordinators(commonCoords)
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/hermeznetwork/hermez-node/common"
|
||||
"github.com/hermeznetwork/hermez-node/db/historydb"
|
||||
"github.com/hermeznetwork/hermez-node/log"
|
||||
"github.com/hermeznetwork/tracerr"
|
||||
)
|
||||
|
||||
@@ -17,11 +18,45 @@ type Updater struct {
|
||||
vars common.SCVariablesPtr
|
||||
consts historydb.Constants
|
||||
rw sync.RWMutex
|
||||
rfp *RecommendedFeePolicy
|
||||
}
|
||||
|
||||
// RecommendedFeePolicy describes how the recommended fee is calculated
|
||||
type RecommendedFeePolicy struct {
|
||||
PolicyType RecommendedFeePolicyType
|
||||
StaticValue float64
|
||||
}
|
||||
|
||||
// RecommendedFeePolicyType describes the different available recommended fee strategies
|
||||
type RecommendedFeePolicyType string
|
||||
|
||||
const (
|
||||
// Always give the same StaticValue as recommended fee
|
||||
RecommendedFeePolicyTypeStatic RecommendedFeePolicyType = "Static"
|
||||
// Set the recommended fee using the average fee of the last hour
|
||||
RecommendedFeePolicyTypeAvgLastHour RecommendedFeePolicyType = "AvgLastHour"
|
||||
)
|
||||
|
||||
func (rfp *RecommendedFeePolicy) valid() bool {
|
||||
switch rfp.PolicyType {
|
||||
case RecommendedFeePolicyTypeStatic:
|
||||
if rfp.StaticValue == 0 {
|
||||
log.Warn("RcommendedFee is set to 0 USD, and the policy is static")
|
||||
}
|
||||
return true
|
||||
case RecommendedFeePolicyTypeAvgLastHour:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// NewUpdater creates a new Updater
|
||||
func NewUpdater(hdb *historydb.HistoryDB, config *historydb.NodeConfig, vars *common.SCVariables,
|
||||
consts *historydb.Constants) *Updater {
|
||||
consts *historydb.Constants, rfp *RecommendedFeePolicy) (*Updater, error) {
|
||||
if ok := rfp.valid(); !ok {
|
||||
return nil, tracerr.New("Invalid recommende fee policy")
|
||||
}
|
||||
u := Updater{
|
||||
hdb: hdb,
|
||||
config: *config,
|
||||
@@ -31,9 +66,10 @@ func NewUpdater(hdb *historydb.HistoryDB, config *historydb.NodeConfig, vars *co
|
||||
ForgeDelay: config.ForgeDelay,
|
||||
},
|
||||
},
|
||||
rfp: rfp,
|
||||
}
|
||||
u.SetSCVars(vars.AsPtr())
|
||||
return &u
|
||||
return &u, nil
|
||||
}
|
||||
|
||||
// Store the State in the HistoryDB
|
||||
@@ -65,13 +101,27 @@ func (u *Updater) SetSCVars(vars *common.SCVariablesPtr) {
|
||||
|
||||
// UpdateRecommendedFee update Status.RecommendedFee information
|
||||
func (u *Updater) UpdateRecommendedFee() error {
|
||||
recommendedFee, err := u.hdb.GetRecommendedFee(u.config.MinFeeUSD, u.config.MaxFeeUSD)
|
||||
if err != nil {
|
||||
return tracerr.Wrap(err)
|
||||
switch u.rfp.PolicyType {
|
||||
case RecommendedFeePolicyTypeStatic:
|
||||
u.rw.Lock()
|
||||
u.state.RecommendedFee = common.RecommendedFee{
|
||||
ExistingAccount: u.rfp.StaticValue,
|
||||
CreatesAccount: u.rfp.StaticValue,
|
||||
CreatesAccountInternal: u.rfp.StaticValue,
|
||||
}
|
||||
u.rw.Unlock()
|
||||
case RecommendedFeePolicyTypeAvgLastHour:
|
||||
recommendedFee, err := u.hdb.GetRecommendedFee(u.config.MinFeeUSD, u.config.MaxFeeUSD)
|
||||
if err != nil {
|
||||
return tracerr.Wrap(err)
|
||||
}
|
||||
u.rw.Lock()
|
||||
u.state.RecommendedFee = *recommendedFee
|
||||
u.rw.Unlock()
|
||||
default:
|
||||
return tracerr.New("Invalid recommende fee policy")
|
||||
}
|
||||
u.rw.Lock()
|
||||
u.state.RecommendedFee = *recommendedFee
|
||||
u.rw.Unlock()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -59,17 +59,21 @@ externalDocs:
|
||||
description: Find out more about Hermez network.
|
||||
url: 'https://hermez.io'
|
||||
servers:
|
||||
- description: Hosted mock up
|
||||
url: https://apimock.hermez.network/v1
|
||||
- description: Localhost mock Up
|
||||
url: http://localhost:4010/v1
|
||||
- description: Hosted mock up, returns fake data useful for development
|
||||
url: https://apimock.hermez.network
|
||||
- description: Localhost mock up, returns fake data useful for development
|
||||
url: http://localhost:4010
|
||||
- description: Testnet (Rinkeby) server
|
||||
url: https://api.testnet.hermez.io
|
||||
- description: Mainnet (Ethereum) server, use it carefully, specially if attempting to send transactions. You could lose money!
|
||||
url: https://api.hermez.io
|
||||
tags:
|
||||
- name: Coordinator
|
||||
description: Endpoints used by the nodes running in coordinator mode. They are used to interact with the network.
|
||||
- name: Explorer
|
||||
description: Endpoints used by the nodes running in explorer mode. They are used to get information of the netwrok.
|
||||
paths:
|
||||
'/account-creation-authorization':
|
||||
'/v1/account-creation-authorization':
|
||||
post:
|
||||
tags:
|
||||
- Coordinator
|
||||
@@ -99,7 +103,7 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error500'
|
||||
'/account-creation-authorization/{hezEthereumAddress}':
|
||||
'/v1/account-creation-authorization/{hezEthereumAddress}':
|
||||
get:
|
||||
tags:
|
||||
- Coordinator
|
||||
@@ -139,7 +143,7 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error500'
|
||||
'/accounts':
|
||||
'/v1/accounts':
|
||||
get:
|
||||
tags:
|
||||
- Explorer
|
||||
@@ -210,7 +214,7 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error500'
|
||||
'/accounts/{accountIndex}':
|
||||
'/v1/accounts/{accountIndex}':
|
||||
get:
|
||||
tags:
|
||||
- Explorer
|
||||
@@ -249,7 +253,7 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error500'
|
||||
'/exits':
|
||||
'/v1/exits':
|
||||
get:
|
||||
tags:
|
||||
- Explorer
|
||||
@@ -336,7 +340,7 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error500'
|
||||
'/exits/{batchNum}/{accountIndex}':
|
||||
'/v1/exits/{batchNum}/{accountIndex}':
|
||||
get:
|
||||
tags:
|
||||
- Explorer
|
||||
@@ -381,7 +385,7 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error500'
|
||||
'/transactions-pool':
|
||||
'/v1/transactions-pool':
|
||||
post:
|
||||
tags:
|
||||
- Coordinator
|
||||
@@ -415,7 +419,7 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error500'
|
||||
'/transactions-pool/{id}':
|
||||
'/v1/transactions-pool/{id}':
|
||||
get:
|
||||
tags:
|
||||
- Coordinator
|
||||
@@ -458,7 +462,7 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error500'
|
||||
'/transactions-history':
|
||||
'/v1/transactions-history':
|
||||
get:
|
||||
tags:
|
||||
- Explorer
|
||||
@@ -548,7 +552,7 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error500'
|
||||
'/transactions-history/{id}':
|
||||
'/v1/transactions-history/{id}':
|
||||
get:
|
||||
tags:
|
||||
- Explorer
|
||||
@@ -588,7 +592,7 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error500'
|
||||
'/batches':
|
||||
'/v1/batches':
|
||||
get:
|
||||
tags:
|
||||
- Explorer
|
||||
@@ -664,7 +668,7 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error500'
|
||||
'/batches/{batchNum}':
|
||||
'/v1/batches/{batchNum}':
|
||||
get:
|
||||
tags:
|
||||
- Explorer
|
||||
@@ -704,7 +708,7 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error500'
|
||||
'/full-batches/{batchNum}':
|
||||
'/v1/full-batches/{batchNum}':
|
||||
get:
|
||||
tags:
|
||||
- Explorer
|
||||
@@ -745,7 +749,7 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error500'
|
||||
'/slots':
|
||||
'/v1/slots':
|
||||
get:
|
||||
tags:
|
||||
- Explorer
|
||||
@@ -821,7 +825,7 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error500'
|
||||
'/slots/{slotNum}':
|
||||
'/v1/slots/{slotNum}':
|
||||
get:
|
||||
tags:
|
||||
- Explorer
|
||||
@@ -861,7 +865,7 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error500'
|
||||
'/bids':
|
||||
'/v1/bids':
|
||||
get:
|
||||
tags:
|
||||
- Explorer
|
||||
@@ -925,7 +929,7 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error500'
|
||||
'/state':
|
||||
'/v1/state':
|
||||
get:
|
||||
tags:
|
||||
- Explorer
|
||||
@@ -951,7 +955,7 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error500'
|
||||
'/config':
|
||||
'/v1/config':
|
||||
get:
|
||||
tags:
|
||||
- Explorer
|
||||
@@ -971,7 +975,7 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error500'
|
||||
'/tokens':
|
||||
'/v1/tokens':
|
||||
get:
|
||||
tags:
|
||||
- Explorer
|
||||
@@ -1044,7 +1048,7 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error500'
|
||||
'/tokens/{id}':
|
||||
'/v1/tokens/{id}':
|
||||
get:
|
||||
tags:
|
||||
- Explorer
|
||||
@@ -1083,7 +1087,7 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error500'
|
||||
'/coordinators':
|
||||
'/v1/coordinators':
|
||||
get:
|
||||
tags:
|
||||
- Explorer
|
||||
|
||||
@@ -73,6 +73,9 @@ of the node configuration. Please, check the `type APIServer` at
|
||||
monitor the size of the folder to avoid running out of space.
|
||||
- The node requires a PostgreSQL database. The parameters of the server and
|
||||
database must be set in the `PostgreSQL` section.
|
||||
- The node requires a web3 RPC server to work. The node has only been tested
|
||||
with geth and may not work correctly with other ethereum nodes
|
||||
implementations.
|
||||
|
||||
## Building
|
||||
|
||||
|
||||
@@ -145,3 +145,11 @@ Coordinator = true
|
||||
BatchPath = "/tmp/iden3-test/hermez/batchesdebug"
|
||||
LightScrypt = true
|
||||
# RollupVerifierIndex = 0
|
||||
|
||||
[RecommendedFeePolicy]
|
||||
# Strategy used to calculate the recommended fee that the API will expose.
|
||||
# Available options:
|
||||
# - Static: always return the same value (StaticValue) in USD
|
||||
# - AvgLastHour: calculate using the average fee of the forged transactions during the last hour
|
||||
PolicyType = "Static"
|
||||
StaticValue = 0.99
|
||||
@@ -35,18 +35,18 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
// Version represents the program based on the git tag
|
||||
Version = "v0.1.0"
|
||||
// Build represents the program based on the git commit
|
||||
Build = "dev"
|
||||
// Date represents the date of application was built
|
||||
Date = ""
|
||||
// version represents the program based on the git tag
|
||||
version = "v0.1.0"
|
||||
// commit represents the program based on the git commit
|
||||
commit = "dev"
|
||||
// date represents the date of application was built
|
||||
date = ""
|
||||
)
|
||||
|
||||
func cmdVersion(c *cli.Context) error {
|
||||
fmt.Printf("Version = \"%v\"\n", Version)
|
||||
fmt.Printf("Build = \"%v\"\n", Build)
|
||||
fmt.Printf("Date = \"%v\"\n", Date)
|
||||
fmt.Printf("Version = \"%v\"\n", version)
|
||||
fmt.Printf("Build = \"%v\"\n", commit)
|
||||
fmt.Printf("Date = \"%v\"\n", date)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -365,6 +365,7 @@ func getConfig(c *cli.Context) (*Config, error) {
|
||||
}
|
||||
case modeCoord:
|
||||
cfg.mode = node.ModeCoordinator
|
||||
fmt.Println("LOADING CFG")
|
||||
cfg.node, err = config.LoadNode(nodeCfgPath, true)
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
@@ -421,7 +422,7 @@ func getConfigAPIServer(c *cli.Context) (*ConfigAPIServer, error) {
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
app.Name = "hermez-node"
|
||||
app.Version = Version
|
||||
app.Version = version
|
||||
flags := []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: flagMode,
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||
"github.com/hermeznetwork/hermez-node/api/stateapiupdater"
|
||||
"github.com/hermeznetwork/hermez-node/common"
|
||||
"github.com/hermeznetwork/hermez-node/priceupdater"
|
||||
"github.com/hermeznetwork/tracerr"
|
||||
@@ -299,7 +300,8 @@ type Node struct {
|
||||
} `validate:"required"`
|
||||
PostgreSQL PostgreSQL `validate:"required"`
|
||||
Web3 struct {
|
||||
// URL is the URL of the web3 ethereum-node RPC server
|
||||
// URL is the URL of the web3 ethereum-node RPC server. Only
|
||||
// geth is officially supported.
|
||||
URL string `validate:"required"`
|
||||
} `validate:"required"`
|
||||
Synchronizer struct {
|
||||
@@ -346,8 +348,9 @@ type Node struct {
|
||||
// can wait to stablish a SQL connection
|
||||
SQLConnectionTimeout Duration
|
||||
} `validate:"required"`
|
||||
Debug NodeDebug `validate:"required"`
|
||||
Coordinator Coordinator `validate:"-"`
|
||||
RecommendedFeePolicy stateapiupdater.RecommendedFeePolicy `validate:"required"`
|
||||
Debug NodeDebug `validate:"required"`
|
||||
Coordinator Coordinator `validate:"-"`
|
||||
}
|
||||
|
||||
// APIServer is the api server configuration parameters
|
||||
|
||||
@@ -1,3 +1,43 @@
|
||||
/*
|
||||
Package coordinator handles all the logic related to forging batches as a
|
||||
coordinator in the hermez network.
|
||||
|
||||
The forging of batches is done with a pipeline in order to allow multiple
|
||||
batches being forged in parallel. The maximum number of batches that can be
|
||||
forged in parallel is determined by the number of available proof servers.
|
||||
|
||||
The Coordinator begins with the pipeline stopped. The main Coordinator
|
||||
goroutine keeps listening for synchronizer events sent by the node package,
|
||||
which allow the coordinator to determine if the configured forger address is
|
||||
allowed to forge at the current block or not. When the forger address becomes
|
||||
allowed to forge, the pipeline is started, and when it terminates being allowed
|
||||
to forge, the pipeline is stopped.
|
||||
|
||||
The Pipeline consists of two goroutines. The first one is in charge of
|
||||
preparing a batch internally, which involves making a selection of transactions
|
||||
and calculating the ZKInputs for the batch proof, and sending these ZKInputs to
|
||||
an idle proof server. This goroutine will keep preparing batches while there
|
||||
are idle proof servers, if the forging policy determines that a batch should be
|
||||
forged in the current state. The second goroutine is in charge of waiting for
|
||||
the proof server to finish computing the proof, retreiving it, prepare the
|
||||
arguments for the `forgeBatch` Rollup transaction, and sending the result to
|
||||
the TxManager. All the batch information moves between functions and
|
||||
goroutines via the BatchInfo struct.
|
||||
|
||||
Finally, the TxManager contains a single goroutine that makes forgeBatch
|
||||
ethereum transactions for the batches sent by the Pipeline, and keeps them in a
|
||||
list to check them periodically. In the periodic checks, the ethereum
|
||||
transaction is checked for successfulness, and it's only forgotten after a
|
||||
number of confirmation blocks have passed after being successfully mined. At
|
||||
any point if a transaction failure is detected, the TxManager can signal the
|
||||
Coordinator to reset the Pipeline in order to reforge the failed batches.
|
||||
|
||||
The Coordinator goroutine acts as a manager. The synchronizer events (which
|
||||
notify about new blocks and associated new state) that it receives are
|
||||
broadcasted to the Pipeline and the TxManager. This allows the Coordinator,
|
||||
Pipeline and TxManager to have a copy of the current hermez network state
|
||||
required to perform their duties.
|
||||
*/
|
||||
package coordinator
|
||||
|
||||
import (
|
||||
|
||||
26
node/node.go
26
node/node.go
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
Package node does the initialization of all the required objects to either run
|
||||
as a synchronizer or as a coordinator.
|
||||
|
||||
The Node contains several goroutines that run in the background or that
|
||||
periodically perform tasks. One of this goroutines periodically calls the
|
||||
`Synchronizer.Sync` function, allowing the synchronization of one block at a
|
||||
time. After every call to `Synchronizer.Sync`, the Node sends a message to the
|
||||
Coordinator to notify it about the new synced block (and associated state) or
|
||||
reorg (and resetted state) in case one happens.
|
||||
|
||||
Other goroutines perform tasks such as: updating the token prices, update
|
||||
metrics stored in the historyDB, update recommended fee stored in the
|
||||
historyDB, run the http API server, run the debug http API server, etc.
|
||||
*/
|
||||
package node
|
||||
|
||||
import (
|
||||
@@ -273,7 +288,16 @@ func NewNode(mode Mode, cfg *config.Node) (*Node, error) {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
|
||||
stateAPIUpdater := stateapiupdater.NewUpdater(historyDB, &hdbNodeCfg, initSCVars, &hdbConsts)
|
||||
stateAPIUpdater, err := stateapiupdater.NewUpdater(
|
||||
historyDB,
|
||||
&hdbNodeCfg,
|
||||
initSCVars,
|
||||
&hdbConsts,
|
||||
&cfg.RecommendedFeePolicy,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
|
||||
var coord *coordinator.Coordinator
|
||||
if mode == ModeCoordinator {
|
||||
|
||||
@@ -1,3 +1,35 @@
|
||||
/*
|
||||
Package synchronizer synchronizes the hermez network state by querying events
|
||||
emitted by the three smart contracts: `Hermez.sol` (referred as Rollup here),
|
||||
`HermezAuctionProtocol.sol` (referred as Auction here) and
|
||||
`WithdrawalDelayer.sol` (referred as WDelayer here).
|
||||
|
||||
The main entry point for synchronization is the `Sync` function, which at most
|
||||
will synchronize one ethereum block, and all the hermez events that happened in
|
||||
that block. During a `Sync` call, a reorg can be detected; in such case, uncle
|
||||
blocks will be discarded, and only in a future `Sync` call correct blocks will
|
||||
be synced.
|
||||
|
||||
The synchronization of the events in each smart contracts are done
|
||||
in the methods `rollupSync`, `auctionSync` and `wdelayerSync`, which in turn
|
||||
use the interface code to read each smart contract state and events found in
|
||||
"github.com/hermeznetwork/hermez-node/eth". After these three methods are
|
||||
called, an object of type `common.BlockData` is built containing all the
|
||||
updates and events that happened in that block, and it is inserted in the
|
||||
HistoryDB in a single SQL transaction.
|
||||
|
||||
`rollupSync` is the method that synchronizes batches sent via the `forgeBatch`
|
||||
transaction in `Hermez.sol`. In `rollupSync`, for every batch, the accounts
|
||||
state is updated in the StateDB by processing all transactions that have been
|
||||
forged in that batch.
|
||||
|
||||
The consistency of the stored data is guaranteed by the HistoryDB: All the
|
||||
block information is inserted in a single SQL transaction at the end of the
|
||||
`Sync` method, once the StateDB has been updated. And every time the
|
||||
Synchronizer starts, it continues from the last block in the HistoryDB. The
|
||||
StateDB stores updates organized by checkpoints for every batch, and each batch
|
||||
is only accessed if it appears in the HistoryDB.
|
||||
*/
|
||||
package synchronizer
|
||||
|
||||
import (
|
||||
@@ -23,12 +55,6 @@ const (
|
||||
// errStrUnknownBlock is the string returned by geth when querying an
|
||||
// unknown block
|
||||
errStrUnknownBlock = "unknown block"
|
||||
// updateEthBlockNumThreshold is a threshold of number of ethereum blocks left to synchronize, such that
|
||||
// if we have more blocks to sync than the defined value we can aggressively skip calling UpdateEth
|
||||
updateEthBlockNumThreshold = 100
|
||||
// While having more blocks to sync than updateEthBlockNumThreshold, UpdateEth will be called once in a
|
||||
// defined number of blocks
|
||||
updateEthFrequencyDivider = 100
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -534,11 +560,8 @@ func (s *Synchronizer) Sync(ctx context.Context,
|
||||
log.Debugf("ethBlock: num: %v, parent: %v, hash: %v",
|
||||
ethBlock.Num, ethBlock.ParentHash.String(), ethBlock.Hash.String())
|
||||
|
||||
if nextBlockNum+updateEthBlockNumThreshold >= s.stats.Eth.LastBlock.Num ||
|
||||
nextBlockNum%updateEthFrequencyDivider == 0 {
|
||||
if err := s.stats.UpdateEth(s.ethClient); err != nil {
|
||||
return nil, nil, tracerr.Wrap(err)
|
||||
}
|
||||
if err := s.stats.UpdateEth(s.ethClient); err != nil {
|
||||
return nil, nil, tracerr.Wrap(err)
|
||||
}
|
||||
|
||||
log.Debugw("Syncing...",
|
||||
|
||||
Reference in New Issue
Block a user