Skip to content

Commit

Permalink
Prepare Bor package for testing (#416)
Browse files Browse the repository at this point in the history
* Limit state sync by gas

* Added logging for state-sync total gas usage

* Added number of event-records in log

* Minor Changes

* Minor Fix

* Adding individual gasUsed

* Minor Fix

* it works

* fix tests

* log wiggle and delay with block number

* log delays as numbers

* linters

* fix tests

* restore linters for the project

* fix linters

* fix

* fix

* fix

* linters

* generation

* fix tests

* remove heimdall wrapper response

* linters

* remove possible collisions

* remove possible collisions

* remove possible collisions

* tests for unique address generation

* generalize set

* bor miner tests got restored

* fixes after CR

* final step and mining test

* fix

* fix e2e

* more tests for Heimdall requests

* fix linters

Co-authored-by: Ferran <ferranbt@protonmail.com>
Co-authored-by: Shivam Sharma <shivam691999@gmail.com>
  • Loading branch information
3 people authored Jun 8, 2022
1 parent 8808c23 commit 9c8bf51
Show file tree
Hide file tree
Showing 68 changed files with 2,508 additions and 1,172 deletions.
3 changes: 2 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This file configures github.com/golangci/golangci-lint.

run:
go: '1.18'
timeout: 20m
tests: true
# default is true. Enables skipping of directories:
Expand Down Expand Up @@ -183,4 +184,4 @@ issues:
max-issues-per-linter: 0
max-same-issues: 0
#new: true
# new-from-rev: origin/master
new-from-rev: origin/master
20 changes: 11 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ escape:
cd $(path) && go test -gcflags "-m -m" -run none -bench=BenchmarkJumpdest* -benchmem -memprofile mem.out

lint:
@./build/bin/golangci-lint run --config ./.golangci.yml \
internal/cli \
consensus/bor
@./build/bin/golangci-lint run --config ./.golangci.yml

lintci-deps:
rm -f ./build/bin/golangci-lint
Expand All @@ -87,16 +85,20 @@ clean:
# You need to put $GOBIN (or $GOPATH/bin) in your PATH to use 'go generate'.

devtools:
env GOBIN= go install golang.org/x/tools/cmd/stringer@latest
env GOBIN= go install github.com/kevinburke/go-bindata/go-bindata@latest
env GOBIN= go install github.com/fjl/gencodec@latest
env GOBIN= go install github.com/golang/protobuf/protoc-gen-go@latest
env GOBIN= go install ./cmd/abigen
# Notice! If you adding new binary - add it also to tests/deps/fake.go file
$(GOBUILD) -o $(GOBIN)/stringer github.com/golang.org/x/tools/cmd/stringer
$(GOBUILD) -o $(GOBIN)/go-bindata github.com/kevinburke/go-bindata/go-bindata
$(GOBUILD) -o $(GOBIN)/codecgen github.com/ugorji/go/codec/codecgen
$(GOBUILD) -o $(GOBIN)/abigen ./cmd/abigen
$(GOBUILD) -o $(GOBIN)/mockgen github.com/golang/mock/mockgen
$(GOBUILD) -o $(GOBIN)/protoc-gen-go github.com/golang/protobuf/protoc-gen-go
PATH=$(GOBIN):$(PATH) go generate ./common
PATH=$(GOBIN):$(PATH) go generate ./core/types
PATH=$(GOBIN):$(PATH) go generate ./consensus/bor
@type "solc" 2> /dev/null || echo 'Please install solc'
@type "protoc" 2> /dev/null || echo 'Please install protoc'

# Cross Compilation Targets (xgo)

geth-cross: geth-linux geth-darwin geth-windows geth-android geth-ios
@echo "Full cross compilation done:"
@ls -ld $(GOBIN)/geth-*
Expand Down
12 changes: 9 additions & 3 deletions cmd/clidoc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const (
)

func main() {

commands := cli.Commands()

dest := flag.String("d", DefaultDir, "Destination directory where the docs will be generated")
Expand All @@ -35,10 +34,12 @@ func main() {

keys := make([]string, len(commands))
i := 0

for k := range commands {
keys[i] = k
i++
}

sort.Strings(keys)

for _, name := range keys {
Expand All @@ -60,12 +61,17 @@ func main() {

func overwriteFile(filePath string, text string) {
log.Printf("Writing to page: %s\n", filePath)

f, err := os.Create(filePath)
if err != nil {
log.Fatalln(err)
}
f.WriteString(text)
if err := f.Close(); err != nil {

if _, err = f.WriteString(text); err != nil {
log.Fatalln(err)
}

if err = f.Close(); err != nil {
log.Fatalln(err)
}
}
28 changes: 28 additions & 0 deletions common/debug/debug.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package debug

import (
"runtime"
)

// Callers returns given number of callers with packages
func Callers(show int) []string {
fpcs := make([]uintptr, show)

n := runtime.Callers(2, fpcs)
if n == 0 {
return nil
}

callers := make([]string, 0, len(fpcs))

for _, p := range fpcs {
caller := runtime.FuncForPC(p - 1)
if caller == nil {
continue
}

callers = append(callers, caller.Name())
}

return callers
}
11 changes: 11 additions & 0 deletions common/set/slice.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package set

func New[T comparable](slice []T) map[T]struct{} {
m := make(map[T]struct{}, len(slice))

for _, el := range slice {
m[el] = struct{}{}
}

return m
}
6 changes: 6 additions & 0 deletions consensus/bor/abi/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package abi

type ABI interface {
Pack(name string, args ...interface{}) ([]byte, error)
UnpackIntoInterface(v interface{}, name string, data []byte) error
}
7 changes: 4 additions & 3 deletions consensus/bor/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/bor/valset"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rpc"
Expand Down Expand Up @@ -206,10 +207,10 @@ func (api *API) GetCurrentProposer() (common.Address, error) {
}

// GetCurrentValidators gets the current validators
func (api *API) GetCurrentValidators() ([]*Validator, error) {
func (api *API) GetCurrentValidators() ([]*valset.Validator, error) {
snap, err := api.GetSnapshot(nil)
if err != nil {
return make([]*Validator, 0), err
return make([]*valset.Validator, 0), err
}

return snap.ValidatorSet.Validators, nil
Expand All @@ -236,7 +237,7 @@ func (api *API) GetRootHash(start uint64, end uint64) (string, error) {
currentHeaderNumber := api.chain.CurrentHeader().Number.Uint64()

if start > end || end > currentHeaderNumber {
return "", &InvalidStartEndBlockError{start, end, currentHeaderNumber}
return "", &valset.InvalidStartEndBlockError{Start: start, End: end, CurrentHeader: currentHeaderNumber}
}

blockHeaders := make([]*types.Header, end-start+1)
Expand Down
14 changes: 14 additions & 0 deletions consensus/bor/api/caller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package api

import (
"context"

"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/internal/ethapi"
"github.com/ethereum/go-ethereum/rpc"
)

//go:generate mockgen -destination=./caller_mock.go -package=api . Caller
type Caller interface {
Call(ctx context.Context, args ethapi.TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *ethapi.StateOverride) (hexutil.Bytes, error)
}
53 changes: 53 additions & 0 deletions consensus/bor/api/caller_mock.go

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

Loading

0 comments on commit 9c8bf51

Please sign in to comment.