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

Commit

Permalink
Merge remote-tracking branch 'origin' into feat/zero
Browse files Browse the repository at this point in the history
  • Loading branch information
vcastellm committed Aug 29, 2023
2 parents 6c2a377 + 4369155 commit 5a737c9
Show file tree
Hide file tree
Showing 109 changed files with 2,677 additions and 1,128 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/e2e-polybft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ jobs:
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: 1.20.x
check-latest: true
cache-dependency-path: go.sum

- name: Run tests
run: make test-e2e-polybft
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/loadtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
- name: Install xk6
run: |
go install go.k6.io/xk6/cmd/xk6@latest
xk6 build --with github.com/distribworks/xk6-ethereum@5c6e782669953f1e5d1f44509e610fb2e3d22238
xk6 build --with github.com/distribworks/xk6-ethereum@v1.0.2
- name: Install JQ
run: |
Expand Down
74 changes: 54 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@

.PHONY: download-submodules
download-submodules:
download-submodules: check-git
git submodule init
git submodule update

.PHONY: check-git
check-git:
@which git > /dev/null || (echo "git is not installed. Please install and try again."; exit 1)

.PHONY: check-go
check-go:
@which go > /dev/null || (echo "Go is not installed.. Please install and try again."; exit 1)

.PHONY: check-protoc
check-protoc:
@which protoc > /dev/null || (echo "protoc is not installed. Please install and try again."; exit 1)

.PHONY: check-lint
check-lint:
@which golangci-lint > /dev/null || (echo "golangci-lint is not installed. Please install and try again."; exit 1)

.PHONY: check-npm
check-npm:
@which npm > /dev/null || (echo "npm is not installed. Please install and try again."; exit 1)

.PHONY: bindata
bindata:
bindata: check-go
go-bindata -pkg chain -o ./chain/chain_bindata.go ./chain/chains

.PHONY: protoc
protoc:
protoc: check-protoc
protoc --go_out=. --go-grpc_out=. -I . -I=./validate --validate_out="lang=go:." \
./server/proto/*.proto \
./network/proto/*.proto \
Expand All @@ -18,7 +37,7 @@ protoc:
./consensus/polybft/**/*.proto

.PHONY: build
build:
build: check-go check-git
$(eval LATEST_VERSION = $(shell git describe --tags --abbrev=0))
$(eval COMMIT_HASH = $(shell git rev-parse HEAD))
$(eval BRANCH = $(shell git rev-parse --abbrev-ref HEAD | tr -d '\040\011\012\015\n'))
Expand All @@ -31,50 +50,45 @@ build:
main.go

.PHONY: lint
lint:
lint: check-lint
golangci-lint run --config .golangci.yml

.PHONY: generate-bsd-licenses
generate-bsd-licenses:
generate-bsd-licenses: check-git
./generate_dependency_licenses.sh BSD-3-Clause,BSD-2-Clause > ./licenses/bsd_licenses.json

.PHONY: test
test:
test: check-go
go test -coverprofile coverage.out -timeout 20m `go list ./... | grep -v e2e`

.PHONY: fuzz-test
fuzz-test:
fuzz-test: check-go
./scripts/fuzzAll

.PHONY: test-e2e
test-e2e:
# We need to build the binary with the race flag enabled
# because it will get picked up and run during e2e tests
# and the e2e tests should error out if any kind of race is found
test-e2e: check-go
go build -race -o artifacts/polygon-edge .
env EDGE_BINARY=${PWD}/artifacts/polygon-edge go test -v -timeout=30m ./e2e/...

.PHONY: test-e2e-polybft
test-e2e-polybft:
# We can not build with race because of a bug in boltdb dependency
test-e2e-polybft: check-go
go build -o artifacts/polygon-edge .
env EDGE_BINARY=${PWD}/artifacts/polygon-edge E2E_TESTS=true E2E_LOGS=true \
go test -v -timeout=1h10m ./e2e-polybft/e2e/...

.PHONY: test-property-polybft
test-property-polybft:
# We can not build with race because of a bug in boltdb dependency
test-property-polybft: check-go
go build -o artifacts/polygon-edge .
env EDGE_BINARY=${PWD}/artifacts/polygon-edge E2E_TESTS=true E2E_LOGS=true go test -v -timeout=30m ./e2e-polybft/property/... \
-rapid.checks=10

.PHONY: compile-core-contracts
compile-core-contracts:
compile-core-contracts: check-npm
cd core-contracts && npm install && npm run compile
$(MAKE) generate-smart-contract-bindings

.PHONY: generate-smart-contract-bindings
generate-smart-contract-bindings:
generate-smart-contract-bindings: check-go
go run ./consensus/polybft/contractsapi/artifacts-gen/main.go
go run ./consensus/polybft/contractsapi/bindings-gen/main.go

Expand All @@ -88,4 +102,24 @@ stop-docker:

.PHONY: destroy-docker
destroy-docker:
./scripts/cluster polybft --docker destroy
./scripts/cluster polybft --docker destroy

.PHONY: help
help:
@echo "Available targets:"
@printf " %-35s - %s\n" "download-submodules" "Initialize and update Git submodules"
@printf " %-35s - %s\n" "bindata" "Generate Go binary data for chain"
@printf " %-35s - %s\n" "protoc" "Compile Protocol Buffers files"
@printf " %-35s - %s\n" "build" "Build the project"
@printf " %-35s - %s\n" "lint" "Run linters on the codebase"
@printf " %-35s - %s\n" "generate-bsd-licenses" "Generate BSD licenses"
@printf " %-35s - %s\n" "test" "Run unit tests"
@printf " %-35s - %s\n" "fuzz-test" "Run fuzz tests"
@printf " %-35s - %s\n" "test-e2e" "Run end-to-end tests"
@printf " %-35s - %s\n" "test-e2e-polybft" "Run end-to-end tests for PolyBFT"
@printf " %-35s - %s\n" "test-property-polybft" "Run property tests for PolyBFT"
@printf " %-35s - %s\n" "compile-core-contracts" "Compile core contracts"
@printf " %-35s - %s\n" "generate-smart-contract-bindings" "Generate smart contract bindings"
@printf " %-35s - %s\n" "run-docker" "Run Docker cluster for PolyBFT"
@printf " %-35s - %s\n" "stop-docker" "Stop Docker cluster for PolyBFT"
@printf " %-35s - %s\n" "destroy-docker" "Destroy Docker cluster for PolyBFT"
11 changes: 11 additions & 0 deletions blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,18 @@ func (b *Blockchain) Close() error {

// CalculateBaseFee calculates the basefee of the header.
func (b *Blockchain) CalculateBaseFee(parent *types.Header) uint64 {
// Return zero base fee is a london hardfork is not enabled
if !b.config.Chain.Params.Forks.IsActive(chain.London, parent.Number) {
return 0
}

// Check if this is the first London hardfork block.
// Should return chain.GenesisBaseFee ins this case.
if parent.BaseFee == 0 {
if b.config.Genesis.BaseFee > 0 {
return b.config.Genesis.BaseFee
}

return chain.GenesisBaseFee
}

Expand Down
36 changes: 16 additions & 20 deletions chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ func (g *Genesis) GenesisHeader() *types.Header {
head.Difficulty = GenesisDifficulty
}

if g.BaseFee == 0 {
head.BaseFee = GenesisBaseFee
}

return head
}

Expand Down Expand Up @@ -132,13 +128,13 @@ func (g *Genesis) MarshalJSON() ([]byte, error) {
var enc Genesis
enc.Nonce = hex.EncodeToHex(g.Nonce[:])

enc.Timestamp = types.EncodeUint64(g.Timestamp)
enc.ExtraData = types.EncodeBytes(g.ExtraData)
enc.Timestamp = common.EncodeUint64(g.Timestamp)
enc.ExtraData = common.EncodeBytes(g.ExtraData)

enc.GasLimit = types.EncodeUint64(g.GasLimit)
enc.Difficulty = types.EncodeUint64(g.Difficulty)
enc.BaseFee = types.EncodeUint64(g.BaseFee)
enc.BaseFeeEM = types.EncodeUint64(g.BaseFeeEM)
enc.GasLimit = common.EncodeUint64(g.GasLimit)
enc.Difficulty = common.EncodeUint64(g.Difficulty)
enc.BaseFee = common.EncodeUint64(g.BaseFee)
enc.BaseFeeEM = common.EncodeUint64(g.BaseFeeEM)

enc.Mixhash = g.Mixhash
enc.Coinbase = g.Coinbase
Expand All @@ -152,8 +148,8 @@ func (g *Genesis) MarshalJSON() ([]byte, error) {
enc.Alloc = &alloc
}

enc.Number = types.EncodeUint64(g.Number)
enc.GasUsed = types.EncodeUint64(g.GasUsed)
enc.Number = common.EncodeUint64(g.Number)
enc.GasUsed = common.EncodeUint64(g.GasUsed)
enc.ParentHash = g.ParentHash

return json.Marshal(&enc)
Expand Down Expand Up @@ -201,7 +197,7 @@ func (g *Genesis) UnmarshalJSON(data []byte) error {
}

if dec.ExtraData != nil {
g.ExtraData, subErr = types.ParseBytes(dec.ExtraData)
g.ExtraData, subErr = common.ParseBytes(dec.ExtraData)
if subErr != nil {
parseError("extradata", subErr)
}
Expand Down Expand Up @@ -288,23 +284,23 @@ func (g *GenesisAccount) MarshalJSON() ([]byte, error) {
obj := &genesisAccountEncoder{}

if g.Code != nil {
obj.Code = types.EncodeBytes(g.Code)
obj.Code = common.EncodeBytes(g.Code)
}

if len(g.Storage) != 0 {
obj.Storage = g.Storage
}

if g.Balance != nil {
obj.Balance = types.EncodeBigInt(g.Balance)
obj.Balance = common.EncodeBigInt(g.Balance)
}

if g.Nonce != 0 {
obj.Nonce = types.EncodeUint64(g.Nonce)
obj.Nonce = common.EncodeUint64(g.Nonce)
}

if g.PrivateKey != nil {
obj.PrivateKey = types.EncodeBytes(g.PrivateKey)
obj.PrivateKey = common.EncodeBytes(g.PrivateKey)
}

return json.Marshal(obj)
Expand Down Expand Up @@ -335,7 +331,7 @@ func (g *GenesisAccount) UnmarshalJSON(data []byte) error {
}

if dec.Code != nil {
g.Code, subErr = types.ParseBytes(dec.Code)
g.Code, subErr = common.ParseBytes(dec.Code)
if subErr != nil {
parseError("code", subErr)
}
Expand All @@ -345,7 +341,7 @@ func (g *GenesisAccount) UnmarshalJSON(data []byte) error {
g.Storage = dec.Storage
}

g.Balance, subErr = types.ParseUint256orHex(dec.Balance)
g.Balance, subErr = common.ParseUint256orHex(dec.Balance)
if subErr != nil {
parseError("balance", subErr)
}
Expand All @@ -357,7 +353,7 @@ func (g *GenesisAccount) UnmarshalJSON(data []byte) error {
}

if dec.PrivateKey != nil {
g.PrivateKey, subErr = types.ParseBytes(dec.PrivateKey)
g.PrivateKey, subErr = common.ParseBytes(dec.PrivateKey)
if subErr != nil {
parseError("privatekey", subErr)
}
Expand Down
1 change: 1 addition & 0 deletions chain/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Params struct {
BlockGasTarget uint64 `json:"blockGasTarget"`

// Access control configuration
AccessListsOwner *types.Address `json:"accessListsOwner,omitempty"`
ContractDeployerAllowList *AddressListConfig `json:"contractDeployerAllowList,omitempty"`
ContractDeployerBlockList *AddressListConfig `json:"contractDeployerBlockList,omitempty"`
TransactionsAllowList *AddressListConfig `json:"transactionsAllowList,omitempty"`
Expand Down
6 changes: 3 additions & 3 deletions command/backup/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/0xPolygon/polygon-edge/archive"
"github.com/0xPolygon/polygon-edge/command"
"github.com/0xPolygon/polygon-edge/command/helper"
"github.com/0xPolygon/polygon-edge/types"
"github.com/0xPolygon/polygon-edge/helper/common"
"github.com/hashicorp/go-hclog"
)

Expand Down Expand Up @@ -41,14 +41,14 @@ type backupParams struct {
func (p *backupParams) validateFlags() error {
var parseErr error

if p.from, parseErr = types.ParseUint64orHex(&p.fromRaw); parseErr != nil {
if p.from, parseErr = common.ParseUint64orHex(&p.fromRaw); parseErr != nil {
return errDecodeRange
}

if p.toRaw != "" {
var parsedTo uint64

if parsedTo, parseErr = types.ParseUint64orHex(&p.toRaw); parseErr != nil {
if parsedTo, parseErr = common.ParseUint64orHex(&p.toRaw); parseErr != nil {
return errDecodeRange
}

Expand Down
25 changes: 9 additions & 16 deletions command/bridge/deposit/erc1155/deposit_erc1155.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/0xPolygon/polygon-edge/command/bridge/common"
"github.com/0xPolygon/polygon-edge/command/rootchain/helper"
"github.com/0xPolygon/polygon-edge/consensus/polybft/contractsapi"
helperCommon "github.com/0xPolygon/polygon-edge/helper/common"
"github.com/0xPolygon/polygon-edge/txrelayer"
"github.com/0xPolygon/polygon-edge/types"
)
Expand Down Expand Up @@ -110,7 +111,7 @@ func runCommand(cmd *cobra.Command, _ []string) {
amountRaw := dp.Amounts[i]
tokenIDRaw := dp.TokenIDs[i]

amount, err := types.ParseUint256orHex(&amountRaw)
amount, err := helperCommon.ParseUint256orHex(&amountRaw)
if err != nil {
outputter.SetError(fmt.Errorf("failed to decode provided amount %s: %w", amountRaw, err))

Expand All @@ -119,7 +120,7 @@ func runCommand(cmd *cobra.Command, _ []string) {

amounts[i] = amount

tokenID, err := types.ParseUint256orHex(&tokenIDRaw)
tokenID, err := helperCommon.ParseUint256orHex(&tokenIDRaw)
if err != nil {
outputter.SetError(fmt.Errorf("failed to decode provided token id %s: %w", tokenIDRaw, err))

Expand Down Expand Up @@ -260,11 +261,8 @@ func createDepositTxn(sender ethgo.Address, receivers []ethgo.Address,

addr := ethgo.Address(types.StringToAddress(dp.PredicateAddr))

return &ethgo.Transaction{
From: sender,
To: &addr,
Input: input,
}, nil
return helper.CreateTransaction(sender, &addr, input,
nil, !dp.ChildChainMintable), nil
}

// createMintTxn encodes parameters for mint function on rootchain token contract
Expand All @@ -282,11 +280,8 @@ func createMintTxn(sender, receiver types.Address, amounts, tokenIDs []*big.Int)

addr := ethgo.Address(types.StringToAddress(dp.TokenAddr))

return &ethgo.Transaction{
From: ethgo.Address(sender),
To: &addr,
Input: input,
}, nil
return helper.CreateTransaction(ethgo.Address(sender), &addr,
input, nil, !dp.ChildChainMintable), nil
}

// createApproveERC1155PredicateTxn sends approve transaction
Expand All @@ -305,8 +300,6 @@ func createApproveERC1155PredicateTxn(rootERC1155Predicate,

addr := ethgo.Address(rootERC1155Token)

return &ethgo.Transaction{
To: &addr,
Input: input,
}, nil
return helper.CreateTransaction(ethgo.ZeroAddress, &addr,
input, nil, !dp.ChildChainMintable), nil
}
Loading

0 comments on commit 5a737c9

Please sign in to comment.