Feature/update go geth sharding (#13)
* Upgrade Geth, Go and add CICD * update ipld-eth-server version * Track validation progress on a channel * Add integration tests * Setup validator config and update instructions to run tests locally * Update readme and tests * Update test to use v4 Infrastructure * Inlcude the env file * Fix config file write * Update DB configuration Co-authored-by: prathamesh0 <prathamesh.musale0@gmail.com> Co-authored-by: Ashwin Phatak <ashwinpphatak@gmail.com>
This commit is contained in:
parent
cc935dc97b
commit
d111dd85db
6
.github/workflows/on-pr.yml
vendored
Normal file
6
.github/workflows/on-pr.yml
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
name: Run all tests
|
||||||
|
on: [pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
run-tests:
|
||||||
|
uses: ./.github/workflows/tests.yml
|
113
.github/workflows/tests.yml
vendored
Normal file
113
.github/workflows/tests.yml
vendored
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
name: Test the stack.
|
||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
|
||||||
|
env:
|
||||||
|
STACK_ORCHESTRATOR_REF: 418957a1f745c921b21286c13bb033f922a91ae9
|
||||||
|
GO_ETHEREUM_REF: "v1.10.18-statediff-4.0.2-alpha"
|
||||||
|
IPLD_ETH_DB_REF: 91d30b9ea1acecd0a7f4307390a98bf3e289b8d7
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
integrationtest:
|
||||||
|
name: Run integration tests
|
||||||
|
env:
|
||||||
|
GOPATH: /tmp/go
|
||||||
|
DB_WRITE: true
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Create GOPATH
|
||||||
|
run: mkdir -p /tmp/go
|
||||||
|
- uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: ">=1.18.0"
|
||||||
|
check-latest: true
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
path: "./ipld-eth-db-validator"
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
ref: ${{ env.STACK_ORCHESTRATOR_REF }}
|
||||||
|
path: "./stack-orchestrator/"
|
||||||
|
repository: vulcanize/stack-orchestrator
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
ref: ${{ env.GO_ETHEREUM_REF }}
|
||||||
|
repository: vulcanize/go-ethereum
|
||||||
|
path: "./go-ethereum/"
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
ref: ${{ env.IPLD_ETH_DB_REF }}
|
||||||
|
repository: vulcanize/ipld-eth-db
|
||||||
|
path: "./ipld-eth-db/"
|
||||||
|
- name: Create config file
|
||||||
|
run: |
|
||||||
|
echo vulcanize_go_ethereum=$GITHUB_WORKSPACE/go-ethereum/ >> ./config.sh
|
||||||
|
echo vulcanize_test_contract=$GITHUB_WORKSPACE/ipld-eth-db-validator/test/contract >> ./config.sh
|
||||||
|
echo vulcanize_ipld_eth_db=$GITHUB_WORKSPACE/ipld-eth-db/ >> ./config.sh
|
||||||
|
echo db_write=$DB_WRITE >> ./config.sh
|
||||||
|
echo go_ethereum_db_dependency=access-node >> ./config.sh
|
||||||
|
echo connecting_db_name=vulcanize_testing_v4 >> ./config.sh
|
||||||
|
cat ./config.sh
|
||||||
|
- name: Build geth
|
||||||
|
run: |
|
||||||
|
cd $GITHUB_WORKSPACE/stack-orchestrator/helper-scripts
|
||||||
|
./compile-geth.sh \
|
||||||
|
-p "$GITHUB_WORKSPACE/config.sh" \
|
||||||
|
-e docker
|
||||||
|
- name: Run docker compose
|
||||||
|
run: |
|
||||||
|
docker-compose \
|
||||||
|
-f "$GITHUB_WORKSPACE/stack-orchestrator/docker/local/docker-compose-db-migration.yml" \
|
||||||
|
-f "$GITHUB_WORKSPACE/stack-orchestrator/docker/local/docker-compose-go-ethereum.yml" \
|
||||||
|
-f "$GITHUB_WORKSPACE/stack-orchestrator/docker/local/docker-compose-contract.yml" \
|
||||||
|
-f "$GITHUB_WORKSPACE/stack-orchestrator/docker/latest/docker-compose-timescale-db.yml" \
|
||||||
|
--env-file "$GITHUB_WORKSPACE/config.sh" \
|
||||||
|
up -d --build
|
||||||
|
- name: Run integration test.
|
||||||
|
run: |
|
||||||
|
cd $GITHUB_WORKSPACE/ipld-eth-db-validator
|
||||||
|
./scripts/run_integration_test.sh
|
||||||
|
|
||||||
|
unittest:
|
||||||
|
name: Run unit tests
|
||||||
|
env:
|
||||||
|
GOPATH: /tmp/go
|
||||||
|
DB_WRITE: true
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Create GOPATH
|
||||||
|
run: mkdir -p /tmp/go
|
||||||
|
- uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: ">=1.18.0"
|
||||||
|
check-latest: true
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
path: "./ipld-eth-db-validator"
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
ref: ${{ env.STACK_ORCHESTRATOR_REF }}
|
||||||
|
path: "./stack-orchestrator/"
|
||||||
|
repository: vulcanize/stack-orchestrator
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
ref: ${{ env.IPLD_ETH_DB_REF }}
|
||||||
|
repository: vulcanize/ipld-eth-db
|
||||||
|
path: "./ipld-eth-db/"
|
||||||
|
- name: Create config file
|
||||||
|
run: |
|
||||||
|
echo vulcanize_ipld_eth_db=$GITHUB_WORKSPACE/ipld-eth-db/ >> ./config.sh
|
||||||
|
echo db_write=$DB_WRITE >> ./config.sh
|
||||||
|
echo connecting_db_name=vulcanize_testing_v4 >> ./config.sh
|
||||||
|
cat ./config.sh
|
||||||
|
- name: Run docker compose
|
||||||
|
run: |
|
||||||
|
docker-compose \
|
||||||
|
-f "$GITHUB_WORKSPACE/stack-orchestrator/docker/local/docker-compose-db-migration.yml" \
|
||||||
|
-f "$GITHUB_WORKSPACE/stack-orchestrator/docker/latest/docker-compose-timescale-db.yml" \
|
||||||
|
--env-file "$GITHUB_WORKSPACE/config.sh" \
|
||||||
|
up -d --build
|
||||||
|
- name: Run unit test.
|
||||||
|
run: |
|
||||||
|
cd $GITHUB_WORKSPACE/ipld-eth-db-validator
|
||||||
|
PGPASSWORD=password DATABASE_USER=vdbm DATABASE_PORT=8066 DATABASE_PASSWORD=password DATABASE_HOSTNAME=127.0.0.1 DATABASE_NAME=vulcanize_testing_v4 make test
|
12
Makefile
12
Makefile
@ -3,22 +3,18 @@ BASE = $(GOPATH)/src/$(PACKAGE)
|
|||||||
PKGS = go list ./... | grep -v "^vendor/"
|
PKGS = go list ./... | grep -v "^vendor/"
|
||||||
|
|
||||||
# Tools
|
# Tools
|
||||||
## Testing library
|
|
||||||
GINKGO = $(BIN)/ginkgo
|
|
||||||
$(BIN)/ginkgo:
|
|
||||||
go install github.com/onsi/ginkgo/ginkgo
|
|
||||||
|
|
||||||
.PHONY: integrationtest
|
.PHONY: integrationtest
|
||||||
integrationtest: | $(GINKGO) $(GOOSE)
|
integrationtest: | $(GOOSE)
|
||||||
go vet ./...
|
go vet ./...
|
||||||
go fmt ./...
|
go fmt ./...
|
||||||
$(GINKGO) -r test/ -v
|
go run github.com/onsi/ginkgo/ginkgo -r test/ -v
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test: | $(GINKGO) $(GOOSE)
|
test: | $(GOOSE)
|
||||||
go vet ./...
|
go vet ./...
|
||||||
go fmt ./...
|
go fmt ./...
|
||||||
$(GINKGO) -r pkg/validator/ validator_test/ -v
|
go run github.com/onsi/ginkgo/ginkgo -r validator_test/ -v
|
||||||
|
|
||||||
build:
|
build:
|
||||||
go fmt ./...
|
go fmt ./...
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
"os/signal"
|
"os/signal"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/statediff"
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
@ -34,20 +33,7 @@ func stateValidator() {
|
|||||||
logWithCommand.Fatal(err)
|
logWithCommand.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
height := viper.GetUint64("validate.block-height")
|
service := validator.NewService(cfg, nil)
|
||||||
if height < 1 {
|
|
||||||
logWithCommand.Fatalf("block height cannot be less the 1")
|
|
||||||
}
|
|
||||||
trail := viper.GetUint64("validate.trail")
|
|
||||||
sleepInterval := viper.GetUint("validate.sleepInterval")
|
|
||||||
|
|
||||||
chainConfigPath := viper.GetString("ethereum.chainConfig")
|
|
||||||
chainCfg, err := statediff.LoadConfig(chainConfigPath)
|
|
||||||
if err != nil {
|
|
||||||
logWithCommand.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
service := validator.NewService(cfg.DB, height, trail, sleepInterval, chainCfg)
|
|
||||||
|
|
||||||
wg := new(sync.WaitGroup)
|
wg := new(sync.WaitGroup)
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
22
go.mod
22
go.mod
@ -1,17 +1,18 @@
|
|||||||
module github.com/vulcanize/ipld-eth-db-validator
|
module github.com/vulcanize/ipld-eth-db-validator
|
||||||
|
|
||||||
go 1.17
|
go 1.18
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/ethereum/go-ethereum v1.10.17
|
github.com/ethereum/go-ethereum v1.10.18
|
||||||
github.com/jmoiron/sqlx v1.3.5
|
github.com/jmoiron/sqlx v1.3.5
|
||||||
github.com/onsi/ginkgo v1.16.5
|
github.com/onsi/ginkgo v1.16.5
|
||||||
github.com/onsi/gomega v1.19.0
|
github.com/onsi/gomega v1.19.0
|
||||||
github.com/sirupsen/logrus v1.8.1
|
github.com/sirupsen/logrus v1.8.1
|
||||||
github.com/spf13/cobra v1.4.0
|
github.com/spf13/cobra v1.4.0
|
||||||
github.com/spf13/viper v1.11.0
|
github.com/spf13/viper v1.11.0
|
||||||
github.com/vulcanize/ipfs-ethdb/v4 v4.0.0-alpha
|
github.com/vulcanize/ipfs-ethdb/v4 v4.0.1-alpha
|
||||||
github.com/vulcanize/ipld-eth-server/v4 v4.0.1-alpha
|
github.com/vulcanize/ipld-eth-server/v3 v3.2.1
|
||||||
|
github.com/vulcanize/ipld-eth-server/v4 v4.0.2-alpha
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
@ -60,7 +61,7 @@ require (
|
|||||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||||
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
|
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
|
||||||
github.com/holiman/uint256 v1.2.0 // indirect
|
github.com/holiman/uint256 v1.2.0 // indirect
|
||||||
github.com/huin/goupnp v1.0.3-0.20220313090229-ca81a64b4204 // indirect
|
github.com/huin/goupnp v1.0.3 // indirect
|
||||||
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||||
github.com/ipfs/bbloom v0.0.4 // indirect
|
github.com/ipfs/bbloom v0.0.4 // indirect
|
||||||
github.com/ipfs/go-bitswap v0.4.0 // indirect
|
github.com/ipfs/go-bitswap v0.4.0 // indirect
|
||||||
@ -171,11 +172,12 @@ require (
|
|||||||
github.com/libp2p/go-ws-transport v0.5.0 // indirect
|
github.com/libp2p/go-ws-transport v0.5.0 // indirect
|
||||||
github.com/libp2p/go-yamux/v2 v2.2.0 // indirect
|
github.com/libp2p/go-yamux/v2 v2.2.0 // indirect
|
||||||
github.com/libp2p/zeroconf/v2 v2.0.0 // indirect
|
github.com/libp2p/zeroconf/v2 v2.0.0 // indirect
|
||||||
github.com/lucas-clemente/quic-go v0.23.0 // indirect
|
github.com/lucas-clemente/quic-go v0.26.0 // indirect
|
||||||
github.com/magiconair/properties v1.8.6 // indirect
|
github.com/magiconair/properties v1.8.6 // indirect
|
||||||
github.com/mailgun/groupcache/v2 v2.3.0 // indirect
|
github.com/mailgun/groupcache/v2 v2.3.0 // indirect
|
||||||
github.com/marten-seemann/qtls-go1-16 v0.1.4 // indirect
|
github.com/marten-seemann/qtls-go1-16 v0.1.5 // indirect
|
||||||
github.com/marten-seemann/qtls-go1-17 v0.1.0 // indirect
|
github.com/marten-seemann/qtls-go1-17 v0.1.1 // indirect
|
||||||
|
github.com/marten-seemann/qtls-go1-18 v0.1.1 // indirect
|
||||||
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect
|
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect
|
||||||
github.com/mattn/go-colorable v0.1.12 // indirect
|
github.com/mattn/go-colorable v0.1.12 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||||
@ -233,7 +235,7 @@ require (
|
|||||||
github.com/tklauser/go-sysconf v0.3.6 // indirect
|
github.com/tklauser/go-sysconf v0.3.6 // indirect
|
||||||
github.com/tklauser/numcpus v0.2.2 // indirect
|
github.com/tklauser/numcpus v0.2.2 // indirect
|
||||||
github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef // indirect
|
github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef // indirect
|
||||||
github.com/vulcanize/eth-ipfs-state-validator/v4 v4.0.0-alpha // indirect
|
github.com/vulcanize/eth-ipfs-state-validator/v4 v4.0.1-alpha // indirect
|
||||||
github.com/whyrusleeping/base32 v0.0.0-20170828182744-c30ac30633cc // indirect
|
github.com/whyrusleeping/base32 v0.0.0-20170828182744-c30ac30633cc // indirect
|
||||||
github.com/whyrusleeping/cbor-gen v0.0.0-20210219115102-f37d292932f2 // indirect
|
github.com/whyrusleeping/cbor-gen v0.0.0-20210219115102-f37d292932f2 // indirect
|
||||||
github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f // indirect
|
github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f // indirect
|
||||||
@ -270,4 +272,4 @@ require (
|
|||||||
lukechampine.com/blake3 v1.1.6 // indirect
|
lukechampine.com/blake3 v1.1.6 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
replace github.com/ethereum/go-ethereum v1.10.17 => github.com/vulcanize/go-ethereum v1.10.17-statediff-4.0.1-alpha
|
replace github.com/ethereum/go-ethereum v1.10.18 => github.com/vulcanize/go-ethereum v1.10.18-statediff-4.0.2-alpha
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
|
"github.com/ethereum/go-ethereum/statediff"
|
||||||
"github.com/ethereum/go-ethereum/statediff/indexer/database/sql/postgres"
|
"github.com/ethereum/go-ethereum/statediff/indexer/database/sql/postgres"
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
@ -59,11 +60,35 @@ var TestChainConfig = ¶ms.ChainConfig{
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
dbConfig postgres.Config
|
dbConfig postgres.Config
|
||||||
DB *sqlx.DB
|
DB *sqlx.DB
|
||||||
|
|
||||||
|
ChainCfg *params.ChainConfig
|
||||||
|
|
||||||
|
BlockNum, Trail uint64
|
||||||
|
SleepInterval uint
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfig() (*Config, error) {
|
func NewConfig() (*Config, error) {
|
||||||
cfg := new(Config)
|
cfg := new(Config)
|
||||||
return cfg, cfg.setupDB()
|
err := cfg.setupDB()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg.BlockNum = viper.GetUint64("validate.block-height")
|
||||||
|
if cfg.BlockNum < 1 {
|
||||||
|
return nil, fmt.Errorf("block height cannot be less the 1")
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg.Trail = viper.GetUint64("validate.trail")
|
||||||
|
cfg.SleepInterval = viper.GetUint("validate.sleepInterval")
|
||||||
|
|
||||||
|
chainConfigPath := viper.GetString("ethereum.chainConfig")
|
||||||
|
cfg.ChainCfg, err = statediff.LoadConfig(chainConfigPath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return cfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) setupDB() error {
|
func (c *Config) setupDB() error {
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
package validator
|
package validator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var errNotSupported = errors.New("this operation is not supported")
|
||||||
|
|
||||||
type database struct {
|
type database struct {
|
||||||
ethDB ethdb.Database
|
ethDB ethdb.Database
|
||||||
}
|
}
|
||||||
@ -105,7 +109,7 @@ func (d *database) NewBatchWithSize(size int) ethdb.Batch {
|
|||||||
return d.ethDB.NewBatchWithSize(size)
|
return d.ethDB.NewBatchWithSize(size)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *database) ReadAncients(fn func(ethdb.AncientReader) error) (err error) {
|
func (d *database) ReadAncients(fn func(ethdb.AncientReaderOp) error) (err error) {
|
||||||
return d.ethDB.ReadAncients(fn)
|
return d.ethDB.ReadAncients(fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,3 +121,8 @@ func (d *database) Close() error {
|
|||||||
func (d *database) NewSnapshot() (ethdb.Snapshot, error) {
|
func (d *database) NewSnapshot() (ethdb.Snapshot, error) {
|
||||||
return d.NewSnapshot()
|
return d.NewSnapshot()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewSnapshot creates a database snapshot based on the current state.
|
||||||
|
func (d *database) AncientDatadir() (string, error) {
|
||||||
|
return "", errNotSupported
|
||||||
|
}
|
||||||
|
@ -41,17 +41,19 @@ type service struct {
|
|||||||
logger *log.Logger
|
logger *log.Logger
|
||||||
chainCfg *params.ChainConfig
|
chainCfg *params.ChainConfig
|
||||||
quitChan chan bool
|
quitChan chan bool
|
||||||
|
progressChan chan uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewService(db *sqlx.DB, blockNum, trailNum uint64, sleepInterval uint, chainCfg *params.ChainConfig) *service {
|
func NewService(cfg *Config, progressChan chan uint64) *service {
|
||||||
return &service{
|
return &service{
|
||||||
db: db,
|
db: cfg.DB,
|
||||||
blockNum: blockNum,
|
blockNum: cfg.BlockNum,
|
||||||
trail: trailNum,
|
trail: cfg.Trail,
|
||||||
sleepInterval: sleepInterval,
|
sleepInterval: cfg.SleepInterval,
|
||||||
logger: log.New(),
|
logger: log.New(),
|
||||||
chainCfg: chainCfg,
|
chainCfg: cfg.ChainCfg,
|
||||||
quitChan: make(chan bool),
|
quitChan: make(chan bool),
|
||||||
|
progressChan: progressChan,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +102,9 @@ func (s *service) Start(ctx context.Context, wg *sync.WaitGroup) {
|
|||||||
select {
|
select {
|
||||||
case <-s.quitChan:
|
case <-s.quitChan:
|
||||||
s.logger.Infof("last validated block %v", idxBlockNum-1)
|
s.logger.Infof("last validated block %v", idxBlockNum-1)
|
||||||
s.logger.Info("stopping ipld-eth-db-validator process")
|
if s.progressChan != nil {
|
||||||
|
close(s.progressChan)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
idxBlockNum, err = s.Validate(ctx, api, idxBlockNum)
|
idxBlockNum, err = s.Validate(ctx, api, idxBlockNum)
|
||||||
@ -115,6 +119,7 @@ func (s *service) Start(ctx context.Context, wg *sync.WaitGroup) {
|
|||||||
|
|
||||||
// Stop is used to gracefully stop the service
|
// Stop is used to gracefully stop the service
|
||||||
func (s *service) Stop() {
|
func (s *service) Stop() {
|
||||||
|
s.logger.Info("stopping ipld-eth-db-validator process")
|
||||||
close(s.quitChan)
|
close(s.quitChan)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,15 +138,10 @@ func (s *service) Validate(ctx context.Context, api *ipldEth.PublicEthAPI, idxBl
|
|||||||
}
|
}
|
||||||
|
|
||||||
s.logger.Infof("state root verified for block %d", idxBlockNum)
|
s.logger.Infof("state root verified for block %d", idxBlockNum)
|
||||||
|
if s.progressChan != nil {
|
||||||
err = ValidateReferentialIntegrity(s.db, idxBlockNum)
|
s.progressChan <- idxBlockNum
|
||||||
if err != nil {
|
|
||||||
s.logger.Errorf("failed to verify referential integrity at block %d", idxBlockNum)
|
|
||||||
return idxBlockNum, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.logger.Infof("referential integrity verified for block %d", idxBlockNum)
|
|
||||||
|
|
||||||
idxBlockNum++
|
idxBlockNum++
|
||||||
} else {
|
} else {
|
||||||
// Sleep / wait for head to move ahead
|
// Sleep / wait for head to move ahead
|
||||||
|
@ -5,10 +5,10 @@ set -o xtrace
|
|||||||
|
|
||||||
export PGPASSWORD=password
|
export PGPASSWORD=password
|
||||||
export DATABASE_USER=vdbm
|
export DATABASE_USER=vdbm
|
||||||
export DATABASE_PORT=8077
|
export DATABASE_PORT=8066
|
||||||
export DATABASE_PASSWORD=password
|
export DATABASE_PASSWORD=password
|
||||||
export DATABASE_HOSTNAME=127.0.0.1
|
export DATABASE_HOSTNAME=127.0.0.1
|
||||||
export DATABASE_NAME=vulcanize_testing
|
export DATABASE_NAME=vulcanize_testing_v4
|
||||||
|
|
||||||
# Wait for containers to be up and execute the integration test.
|
# Wait for containers to be up and execute the integration test.
|
||||||
while [ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:8545)" != "200" ]; do echo "waiting for geth-statediff..." && sleep 5; done && \
|
while [ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:8545)" != "200" ]; do echo "waiting for geth-statediff..." && sleep 5; done && \
|
||||||
|
@ -6,18 +6,18 @@
|
|||||||
|
|
||||||
- Clone [stack-orchestrator](https://github.com/vulcanize/stack-orchestrator) and [go-ethereum](https://github.com/vulcanize/go-ethereum) repositories.
|
- Clone [stack-orchestrator](https://github.com/vulcanize/stack-orchestrator) and [go-ethereum](https://github.com/vulcanize/go-ethereum) repositories.
|
||||||
|
|
||||||
- Checkout [v4 release](https://github.com/vulcanize/go-ethereum/releases/tag/v1.10.17-statediff-4.0.1-alpha) in go-ethereum repo.
|
- Checkout [v4 release](https://github.com/vulcanize/go-ethereum/releases/tag/v1.10.18-statediff-4.0.2-alpha) in go-ethereum repo.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# In go-ethereum repo.
|
# In go-ethereum repo.
|
||||||
git checkout v1.10.17-statediff-4.0.1-alpha
|
git checkout v1.10.18-statediff-4.0.2-alpha
|
||||||
```
|
```
|
||||||
|
|
||||||
- Checkout working commit in stack-orchestrator repo.
|
- Checkout working commit in stack-orchestrator repo.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# In stack-orchestrator repo.
|
# In stack-orchestrator repo.
|
||||||
git checkout 42af57a2963bb6ca55fb5fcb16ed75b39fae60f9
|
git checkout 418957a1f745c921b21286c13bb033f922a91ae9
|
||||||
```
|
```
|
||||||
|
|
||||||
## Run
|
## Run
|
||||||
@ -55,6 +55,10 @@
|
|||||||
vulcanize_test_contract=~/ipld-eth-db-validator/test/contract
|
vulcanize_test_contract=~/ipld-eth-db-validator/test/contract
|
||||||
|
|
||||||
db_write=true
|
db_write=true
|
||||||
|
ipld_eth_server_db_dependency=access-node
|
||||||
|
go_ethereum_db_dependency=access-node
|
||||||
|
|
||||||
|
connecting_db_name=vulcanize_testing_v4
|
||||||
```
|
```
|
||||||
|
|
||||||
- Run stack-orchestrator:
|
- Run stack-orchestrator:
|
||||||
|
29
test/contract/contracts/Test.sol
Normal file
29
test/contract/contracts/Test.sol
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
// SPDX-License-Identifier: AGPL-3.0
|
||||||
|
pragma solidity ^0.8.0;
|
||||||
|
|
||||||
|
contract Test {
|
||||||
|
address payable owner;
|
||||||
|
|
||||||
|
modifier onlyOwner {
|
||||||
|
require(
|
||||||
|
msg.sender == owner,
|
||||||
|
"Only owner can call this function."
|
||||||
|
);
|
||||||
|
_;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint256[100] data;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
owner = payable(msg.sender);
|
||||||
|
data = [1];
|
||||||
|
}
|
||||||
|
|
||||||
|
function Put(uint256 addr, uint256 value) public {
|
||||||
|
data[addr] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
function close() public onlyOwner {
|
||||||
|
selfdestruct(owner);
|
||||||
|
}
|
||||||
|
}
|
@ -63,6 +63,49 @@ fastify.get('/v1/sendEth', async (req, reply) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
fastify.get('/v1/deployTestContract', async (req, reply) => {
|
||||||
|
const testContract = await hre.ethers.getContractFactory("Test");
|
||||||
|
const test = await testContract.deploy();
|
||||||
|
await test.deployed();
|
||||||
|
|
||||||
|
return {
|
||||||
|
address: test.address,
|
||||||
|
txHash: test.deployTransaction.hash,
|
||||||
|
blockNumber: test.deployTransaction.blockNumber,
|
||||||
|
blockHash: test.deployTransaction.blockHash,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
fastify.get('/v1/putTestValue', async (req, reply) => {
|
||||||
|
const addr = req.query.addr;
|
||||||
|
const index = req.query.index;
|
||||||
|
const value = req.query.value;
|
||||||
|
|
||||||
|
const testContract = await hre.ethers.getContractFactory("Test");
|
||||||
|
const test = await testContract.attach(addr);
|
||||||
|
|
||||||
|
const tx = await test.Put(index, value);
|
||||||
|
const receipt = await tx.wait();
|
||||||
|
|
||||||
|
return {
|
||||||
|
blockNumber: receipt.blockNumber,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
fastify.get('/v1/destroyTestContract', async (req, reply) => {
|
||||||
|
const addr = req.query.addr;
|
||||||
|
|
||||||
|
const testContract = await hre.ethers.getContractFactory("Test");
|
||||||
|
const test = await testContract.attach(addr);
|
||||||
|
|
||||||
|
await test.destroy();
|
||||||
|
const blockNum = await hre.ethers.provider.getBlockNumber()
|
||||||
|
|
||||||
|
return {
|
||||||
|
blockNumber: blockNum,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
try {
|
try {
|
||||||
await fastify.listen(3000, '0.0.0.0');
|
await fastify.listen(3000, '0.0.0.0');
|
||||||
|
54
test/helper.go
Normal file
54
test/helper.go
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
package integration
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
ethServerIntegration "github.com/vulcanize/ipld-eth-server/v4/test"
|
||||||
|
)
|
||||||
|
|
||||||
|
type PutResult struct {
|
||||||
|
BlockNumber int64 `json:"blockNumber"`
|
||||||
|
}
|
||||||
|
|
||||||
|
const srvUrl = "http://localhost:3000"
|
||||||
|
|
||||||
|
func DeployTestContract() (*ethServerIntegration.ContractDeployed, error) {
|
||||||
|
ethServerIntegration.DeployContract()
|
||||||
|
res, err := http.Get(fmt.Sprintf("%s/v1/deployTestContract", srvUrl))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer res.Body.Close()
|
||||||
|
|
||||||
|
var contract ethServerIntegration.ContractDeployed
|
||||||
|
decoder := json.NewDecoder(res.Body)
|
||||||
|
|
||||||
|
return &contract, decoder.Decode(&contract)
|
||||||
|
}
|
||||||
|
|
||||||
|
func PutTestValue(addr string, index, value int) (*PutResult, error) {
|
||||||
|
res, err := http.Get(fmt.Sprintf("%s/v1/putTestValue?addr=%s&index=%d&value=%d", srvUrl, addr, index, value))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var blockNumber PutResult
|
||||||
|
decoder := json.NewDecoder(res.Body)
|
||||||
|
|
||||||
|
return &blockNumber, decoder.Decode(&blockNumber)
|
||||||
|
}
|
||||||
|
|
||||||
|
func DestroyTestContract(addr string) (*ethServerIntegration.ContractDestroyed, error) {
|
||||||
|
res, err := http.Get(fmt.Sprintf("%s/v1/destroyTestContract?addr=%s", srvUrl, addr))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer res.Body.Close()
|
||||||
|
|
||||||
|
var data ethServerIntegration.ContractDestroyed
|
||||||
|
decoder := json.NewDecoder(res.Body)
|
||||||
|
|
||||||
|
return &data, decoder.Decode(&data)
|
||||||
|
}
|
@ -2,45 +2,107 @@ package integration_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
"github.com/vulcanize/ipld-eth-db-validator/pkg/validator"
|
"github.com/vulcanize/ipld-eth-db-validator/pkg/validator"
|
||||||
|
integration "github.com/vulcanize/ipld-eth-db-validator/test"
|
||||||
|
|
||||||
"github.com/vulcanize/ipld-eth-server/v4/pkg/shared"
|
"github.com/vulcanize/ipld-eth-server/v4/pkg/shared"
|
||||||
integration "github.com/vulcanize/ipld-eth-server/v4/test"
|
ethServerIntegration "github.com/vulcanize/ipld-eth-server/v4/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
blockNum = 1
|
||||||
trail = 0
|
trail = 0
|
||||||
validatorSleepInterval = uint(5)
|
validatorSleepInterval = uint(5)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
testAddresses = []string{
|
||||||
|
"0x1111111111111111111111111111111111111112",
|
||||||
|
"0x1ca7c995f8eF0A2989BbcE08D5B7Efe50A584aa1",
|
||||||
|
"0x9a4b666af23a2cdb4e5538e1d222a445aeb82134",
|
||||||
|
"0xF7C7AEaECD2349b129d5d15790241c32eeE4607B",
|
||||||
|
"0x992b6E9BFCA1F7b0797Cee10b0170E536EAd3532",
|
||||||
|
"0x29ed93a7454Bc17a8D4A24D0627009eE0849B990",
|
||||||
|
"0x66E3dCA826b04B5d4988F7a37c91c9b1041e579D",
|
||||||
|
"0x96288939Ac7048c27E0E087b02bDaad3cd61b37b",
|
||||||
|
"0xD354280BCd771541c935b15bc04342c26086FE9B",
|
||||||
|
"0x7f887e25688c274E77b8DeB3286A55129B55AF14",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
var _ = Describe("Integration test", func() {
|
var _ = Describe("Integration test", func() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
var contract *integration.ContractDeployed
|
var contract *ethServerIntegration.ContractDeployed
|
||||||
var contractErr error
|
var err error
|
||||||
sleepInterval := 5 * time.Second
|
sleepInterval := 2 * time.Second
|
||||||
|
timeout := 4 * time.Second
|
||||||
|
|
||||||
|
db := shared.SetupDB()
|
||||||
|
cfg := validator.Config{
|
||||||
|
DB: db,
|
||||||
|
BlockNum: blockNum,
|
||||||
|
Trail: trail,
|
||||||
|
SleepInterval: validatorSleepInterval,
|
||||||
|
ChainCfg: validator.IntegrationTestChainConfig,
|
||||||
|
}
|
||||||
|
validationProgressChan := make(chan uint64)
|
||||||
|
service := validator.NewService(&cfg, validationProgressChan)
|
||||||
|
|
||||||
|
wg := new(sync.WaitGroup)
|
||||||
|
|
||||||
|
It("test init", func() {
|
||||||
|
wg.Add(1)
|
||||||
|
go service.Start(ctx, wg)
|
||||||
|
|
||||||
|
// Deploy a dummy contract as the first contract might get deployed at block number 0
|
||||||
|
_, _ = ethServerIntegration.DeployContract()
|
||||||
|
time.Sleep(sleepInterval)
|
||||||
|
})
|
||||||
|
|
||||||
|
defer It("test teardown", func() {
|
||||||
|
service.Stop()
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
|
Expect(validationProgressChan).To(BeClosed())
|
||||||
|
})
|
||||||
|
|
||||||
Describe("Validate state", func() {
|
Describe("Validate state", func() {
|
||||||
BeforeEach(func() {
|
It("performs validation on contract deployment", func() {
|
||||||
// Deploy a dummy contract as the first contract might get deployed at block number 0
|
contract, err = integration.DeployTestContract()
|
||||||
_, _ = integration.DeployContract()
|
Expect(err).ToNot(HaveOccurred())
|
||||||
time.Sleep(sleepInterval)
|
time.Sleep(sleepInterval)
|
||||||
|
|
||||||
contract, contractErr = integration.DeployContract()
|
Expect(validationProgressChan).ToNot(BeClosed())
|
||||||
time.Sleep(sleepInterval)
|
Eventually(validationProgressChan, timeout).Should(Receive(Equal(uint64(contract.BlockNumber))))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("Validate state root", func() {
|
It("performs validation on contract transactions", func() {
|
||||||
Expect(contractErr).ToNot(HaveOccurred())
|
for i := 0; i < 10; i++ {
|
||||||
|
res, txErr := integration.PutTestValue(contract.Address, i, i)
|
||||||
|
Expect(txErr).ToNot(HaveOccurred())
|
||||||
|
time.Sleep(sleepInterval)
|
||||||
|
|
||||||
db := shared.SetupDB()
|
Expect(validationProgressChan).ToNot(BeClosed())
|
||||||
srvc := validator.NewService(db, uint64(contract.BlockNumber), trail, validatorSleepInterval, validator.IntegrationTestChainConfig)
|
Eventually(validationProgressChan, timeout).Should(Receive(Equal(uint64(res.BlockNumber))))
|
||||||
srvc.Start(ctx, nil)
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
It("performs validation on eth transfer transactions", func() {
|
||||||
|
for _, address := range testAddresses {
|
||||||
|
tx, txErr := ethServerIntegration.SendEth(address, "0.01")
|
||||||
|
Expect(txErr).ToNot(HaveOccurred())
|
||||||
|
time.Sleep(sleepInterval)
|
||||||
|
|
||||||
|
Expect(validationProgressChan).ToNot(BeClosed())
|
||||||
|
Eventually(validationProgressChan, timeout).Should(Receive(Equal(uint64(tx.BlockNumber))))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user