Skip to content

Commit

Permalink
v1.1.1 preparations (without proxies support) (#1910)
Browse files Browse the repository at this point in the history
* Revert "Removing tx hash fork (#1904)"

This reverts commit dcfc044.

* Revert "Speed up root chain contracts deployment (#1906)"

This reverts commit 182aadd.

* Revert "Introduce `baseFeeChangeDenom` network parameter (#1872)"

This reverts commit 5241598.

* Revert "Root chain proxy contracts deployment (#1888)"

This reverts commit c49733b.

* Revert "Deploy proxy contracts on genesis (#1855)"

This reverts commit 6d848ed.

* Revert "Expose double signer implementation (#1875)"

This reverts commit 3d2e58f.

* Revert "Fix nightly build script by providing governor-admin flag in the genesis command (#1882)"

This reverts commit b467a12.

* Revert "Minor change that fix merged code (#1879)"

This reverts commit daf9402.

* Revert "[Feature] Double-signing slashing (#1808)"

This reverts commit 06153fb.

* Revert "[RFC-191] On-chain governance (#1519)"

This reverts commit 3cae93a.

* merge fix

* increase timeout for e2e tests

* regenerate SC bindings to update ChildERC20PredicateACLArtifact

* Revert "Evm 785: enable and disable access lists in the runtime (#1839)"

This reverts commit 85af1b3.

---------

Co-authored-by: Stefan Negovanović <stefan@ethernal.tech>
  • Loading branch information
dusan-maksimovic and Stefan-Ethernal authored Sep 19, 2023
1 parent 918f322 commit 7beeb38
Show file tree
Hide file tree
Showing 128 changed files with 1,521 additions and 7,676 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/deploy.nightly.devnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ jobs:
{% endfor %}
BURN_CONTRACT_ADDRESS=0x0000000000000000000000000000000000000000
PROXY_CONTRACTS_ADMIN=0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed
polygon-edge genesis \
--consensus polybft \
Expand All @@ -142,20 +141,16 @@ jobs:
--block-time {{ block_time }}s \
{% for item in hostvars %}{% if (hostvars[item].tags.Role == "validator") %} --validators /dns4/{{ hostvars[item].tags["Name"] }}/tcp/{{ edge_p2p_port }}/p2p/$(cat {{ hostvars[item].tags["Name"] }}.json | jq -r '.[0].node_id'):$(cat {{ hostvars[item].tags["Name"] }}.json | jq -r '.[0].address' | sed 's/^0x//'):$(cat {{ hostvars[item].tags["Name"] }}.json | jq -r '.[0].bls_pubkey') {% endif %}{% endfor %} \
--epoch-size 10 \
--native-token-config MyToken:MTK:18:true:{{ loadtest_account }} \
--governor-admin {{ loadtest_account }} \
--proxy-contracts-admin $PROXY_CONTRACTS_ADMIN
--native-token-config MyToken:MTK:18:true:0x0000000000000000000000000000000000001010
polygon-edge polybft stake-manager-deploy \
--jsonrpc {{ rootchain_json_rpc }} \
--proxy-contracts-admin $PROXY_CONTRACTS_ADMIN \
--test
polygon-edge rootchain deploy \
--stake-manager $(cat genesis.json | jq -r '.params.engine.polybft.bridge.stakeManagerAddr') \
--stake-token $(cat genesis.json | jq -r '.params.engine.polybft.bridge.stakeTokenAddr') \
--json-rpc {{ rootchain_json_rpc }} \
--proxy-contracts-admin $PROXY_CONTRACTS_ADMIN \
--test
polygon-edge rootchain fund \
Expand Down
7 changes: 2 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,8 @@ test-e2e: check-go
.PHONY: test-e2e-polybft
test-e2e-polybft: check-go
go build -o artifacts/polygon-edge .
go build -tags doubleSigner -o artifacts/polygon-edge-double-signer .
env EDGE_BINARY=${PWD}/artifacts/polygon-edge \
BYZANTINE_BINARY=${PWD}/artifacts/polygon-edge-double-signer \
E2E_TESTS=true E2E_LOGS=true \
go test -v -timeout=2h ./e2e-polybft/e2e/...
env EDGE_BINARY=${PWD}/artifacts/polygon-edge E2E_TESTS=true E2E_LOGS=true \
go test -v -timeout=1h30m ./e2e-polybft/e2e/...

.PHONY: test-property-polybft
test-property-polybft: check-go
Expand Down
37 changes: 12 additions & 25 deletions blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ import (
"sync"
"sync/atomic"

"github.com/hashicorp/go-hclog"
lru "github.com/hashicorp/golang-lru"

"github.com/0xPolygon/polygon-edge/blockchain/storage"
"github.com/0xPolygon/polygon-edge/chain"
"github.com/0xPolygon/polygon-edge/helper/common"
"github.com/0xPolygon/polygon-edge/state"
"github.com/0xPolygon/polygon-edge/types"
"github.com/0xPolygon/polygon-edge/types/buildroot"

"github.com/hashicorp/go-hclog"
lru "github.com/hashicorp/golang-lru"
)

const (
// defaultBaseFeeChangeDenom is the value to bound the amount the base fee can change between blocks.
defaultBaseFeeChangeDenom = 8

// blockGasTargetDivisor is the bound divisor of the gas limit, used in update calculations
blockGasTargetDivisor uint64 = 1024

Expand Down Expand Up @@ -89,7 +92,6 @@ type Verifier interface {
ProcessHeaders(headers []*types.Header) error
GetBlockCreator(header *types.Header) (types.Address, error)
PreCommitState(block *types.Block, txn *state.Transition) error
GetLatestChainConfig() (*chain.Params, error)
}

type Executor interface {
Expand Down Expand Up @@ -703,7 +705,7 @@ func (b *Blockchain) verifyBlockBody(block *types.Block) ([]*types.Receipt, erro
}

// Make sure the transactions root matches up
if hash := buildroot.CalculateTransactionsRoot(block.Transactions); hash != block.Header.TxRoot {
if hash := buildroot.CalculateTransactionsRoot(block.Transactions, block.Number()); hash != block.Header.TxRoot {
b.logger.Error(fmt.Sprintf(
"incorrect tx root (expected: %s, actual: %s)",
hash,
Expand Down Expand Up @@ -1360,7 +1362,7 @@ func (b *Blockchain) CalculateBaseFee(parent *types.Header) uint64 {
}

// Check if this is the first London hardfork block.
// Should return chain.GenesisBaseFee in this case.
// Should return chain.GenesisBaseFee ins this case.
if parent.BaseFee == 0 {
if b.config.Genesis.BaseFee > 0 {
return b.config.Genesis.BaseFee
Expand All @@ -1379,37 +1381,22 @@ func (b *Blockchain) CalculateBaseFee(parent *types.Header) uint64 {
// If the parent block used more gas than its target, the baseFee should increase.
if parent.GasUsed > parentGasTarget {
gasUsedDelta := parent.GasUsed - parentGasTarget
baseFeeDelta := b.calcBaseFeeDelta(gasUsedDelta, parentGasTarget, parent.BaseFee)
baseFeeDelta := calcBaseFeeDelta(gasUsedDelta, parentGasTarget, parent.BaseFee)

return parent.BaseFee + common.Max(baseFeeDelta, 1)
}

// Otherwise, if the parent block used less gas than its target, the baseFee should decrease.
gasUsedDelta := parentGasTarget - parent.GasUsed
baseFeeDelta := b.calcBaseFeeDelta(gasUsedDelta, parentGasTarget, parent.BaseFee)
baseFeeDelta := calcBaseFeeDelta(gasUsedDelta, parentGasTarget, parent.BaseFee)

return common.Max(parent.BaseFee-baseFeeDelta, 0)
}

func (b *Blockchain) calcBaseFeeDelta(gasUsedDelta, parentGasTarget, baseFee uint64) uint64 {
baseFeeChangeDenom := chain.BaseFeeChangeDenom

if b.Config().Forks.IsActive(chain.Governance, b.Header().Number) {
chainConfig, err := b.consensus.GetLatestChainConfig()
if err != nil {
b.logger.Error("failed to calculate base fee delta", "error", err)

return baseFeeChangeDenom
}

if chainConfig != nil {
baseFeeChangeDenom = chainConfig.BaseFeeChangeDenom
}
}

func calcBaseFeeDelta(gasUsedDelta, parentGasTarget, baseFee uint64) uint64 {
y := baseFee * gasUsedDelta / parentGasTarget

return y / baseFeeChangeDenom
return y / defaultBaseFeeChangeDenom
}

func (b *Blockchain) writeBatchAndUpdate(
Expand Down
171 changes: 24 additions & 147 deletions blockchain/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ func TestBlockchainWriteBody(t *testing.T) {
},
}

tx.ComputeHash()
tx.ComputeHash(1)
block.Header.ComputeHash()

txFromByTxHash := map[types.Hash]types.Address{}
Expand Down Expand Up @@ -625,7 +625,7 @@ func TestBlockchainWriteBody(t *testing.T) {
},
}

tx.ComputeHash()
tx.ComputeHash(1)
block.Header.ComputeHash()

txFromByTxHash := map[types.Hash]types.Address{}
Expand Down Expand Up @@ -657,7 +657,7 @@ func TestBlockchainWriteBody(t *testing.T) {
},
}

tx.ComputeHash()
tx.ComputeHash(1)
block.Header.ComputeHash()

txFromByTxHash := map[types.Hash]types.Address{
Expand Down Expand Up @@ -692,7 +692,7 @@ func Test_recoverFromFieldsInBlock(t *testing.T) {

computeTxHashes := func(txs ...*types.Transaction) {
for _, tx := range txs {
tx.ComputeHash()
tx.ComputeHash(1)
}
}

Expand Down Expand Up @@ -777,7 +777,7 @@ func Test_recoverFromFieldsInTransactions(t *testing.T) {

computeTxHashes := func(txs ...*types.Transaction) {
for _, tx := range txs {
tx.ComputeHash()
tx.ComputeHash(1)
}
}

Expand Down Expand Up @@ -896,7 +896,7 @@ func TestBlockchainReadBody(t *testing.T) {
V: big.NewInt(1),
}

tx.ComputeHash()
tx.ComputeHash(1)

block := &types.Block{
Header: &types.Header{},
Expand Down Expand Up @@ -1369,127 +1369,19 @@ func TestBlockchain_CalculateBaseFee(t *testing.T) {
parentBaseFee uint64
parentGasLimit uint64
parentGasUsed uint64
elasticityMultiplier uint64
forks *chain.Forks
getLatestConfigFn getChainConfigDelegate
expectedBaseFee uint64
elasticityMultiplier uint64
}{
{
blockNumber: 6,
parentBaseFee: chain.GenesisBaseFee,
parentGasLimit: 20000000,
parentGasUsed: 10000000,
elasticityMultiplier: 2,
expectedBaseFee: chain.GenesisBaseFee,
}, // usage == target
{
blockNumber: 6,
parentBaseFee: chain.GenesisBaseFee,
parentGasLimit: 20000000,
parentGasUsed: 10000000,
elasticityMultiplier: 4,
expectedBaseFee: 1125000000,
}, // usage == target
{
blockNumber: 6,
parentBaseFee: chain.GenesisBaseFee,
parentGasLimit: 20000000,
parentGasUsed: 9000000,
elasticityMultiplier: 2,
expectedBaseFee: 987500000,
}, // usage below target
{
blockNumber: 6,
parentBaseFee: chain.GenesisBaseFee,
parentGasLimit: 20000000,
parentGasUsed: 9000000,
elasticityMultiplier: 4,
expectedBaseFee: 1100000000,
}, // usage below target
{
blockNumber: 6,
parentBaseFee: chain.GenesisBaseFee,
parentGasLimit: 20000000,
parentGasUsed: 11000000,
elasticityMultiplier: 2,
expectedBaseFee: 1012500000,
}, // usage above target
{
blockNumber: 6,
parentBaseFee: chain.GenesisBaseFee,
parentGasLimit: 20000000,
parentGasUsed: 11000000,
elasticityMultiplier: 4,
expectedBaseFee: 1150000000,
}, // usage above target
{
blockNumber: 6,
parentBaseFee: chain.GenesisBaseFee,
parentGasLimit: 20000000,
parentGasUsed: 20000000,
elasticityMultiplier: 2,
expectedBaseFee: 1125000000,
}, // usage full
{
blockNumber: 6,
parentBaseFee: chain.GenesisBaseFee,
parentGasLimit: 20000000,
parentGasUsed: 20000000,
elasticityMultiplier: 4,
expectedBaseFee: 1375000000,
}, // usage full
{
blockNumber: 6,
parentBaseFee: chain.GenesisBaseFee,
parentGasLimit: 20000000,
parentGasUsed: 0,
elasticityMultiplier: 2,
expectedBaseFee: 875000000,
}, // usage 0
{
blockNumber: 6,
parentBaseFee: chain.GenesisBaseFee,
parentGasLimit: 20000000,
parentGasUsed: 0,
elasticityMultiplier: 4,
expectedBaseFee: 875000000,
}, // usage 0
{
blockNumber: 6,
forks: &chain.Forks{chain.London: chain.NewFork(10)},
expectedBaseFee: 0,
}, // London hard fork disabled
{
blockNumber: 6,
parentBaseFee: 0,
expectedBaseFee: 10,
},
// first block with London hard fork
// (return base fee value configured in the genesis)
{
blockNumber: 6,
parentBaseFee: chain.GenesisBaseFee,
parentGasLimit: 20000000,
parentGasUsed: 10000000,
elasticityMultiplier: 4,
forks: chain.AllForksEnabled,
getLatestConfigFn: func() (*chain.Params, error) {
return &chain.Params{BaseFeeChangeDenom: 4}, nil
},
expectedBaseFee: 1250000000,
}, // governance hard fork enabled
{
blockNumber: 6,
parentBaseFee: chain.GenesisBaseFee,
parentGasLimit: 20000000,
parentGasUsed: 10000000,
elasticityMultiplier: 4,
forks: chain.AllForksEnabled,
getLatestConfigFn: func() (*chain.Params, error) {
return nil, errors.New("failed to retrieve chain config")
},
expectedBaseFee: 1000000008,
}, // governance hard fork enabled
{6, chain.GenesisBaseFee, 20000000, 10000000, chain.GenesisBaseFee, 2}, // usage == target
{6, chain.GenesisBaseFee, 20000000, 10000000, 1125000000, 4}, // usage == target
{6, chain.GenesisBaseFee, 20000000, 9000000, 987500000, 2}, // usage below target
{6, chain.GenesisBaseFee, 20000000, 9000000, 1100000000, 4}, // usage below target
{6, chain.GenesisBaseFee, 20000000, 11000000, 1012500000, 2}, // usage above target
{6, chain.GenesisBaseFee, 20000000, 11000000, 1150000000, 4}, // usage above target
{6, chain.GenesisBaseFee, 20000000, 20000000, 1125000000, 2}, // usage full
{6, chain.GenesisBaseFee, 20000000, 20000000, 1375000000, 4}, // usage full
{6, chain.GenesisBaseFee, 20000000, 0, 875000000, 2}, // usage 0
{6, chain.GenesisBaseFee, 20000000, 0, 875000000, 4}, // usage 0
}

for i, test := range tests {
Expand All @@ -1498,34 +1390,19 @@ func TestBlockchain_CalculateBaseFee(t *testing.T) {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
t.Parallel()

forks := &chain.Forks{
chain.London: chain.NewFork(5),
}

if test.forks != nil {
forks = test.forks
}

blockchain := &Blockchain{
logger: hclog.NewNullLogger(),
blockchain := Blockchain{
config: &chain.Chain{
Params: &chain.Params{Forks: forks},
Params: &chain.Params{
Forks: &chain.Forks{
chain.London: chain.NewFork(5),
},
},
Genesis: &chain.Genesis{
BaseFee: 10,
BaseFeeEM: test.elasticityMultiplier,
},
},
}

blockchain.setCurrentHeader(&types.Header{
Number: test.blockNumber + 1,
GasLimit: test.parentGasLimit,
GasUsed: test.parentGasUsed,
BaseFee: test.parentBaseFee,
}, big.NewInt(1))

blockchain.SetConsensus(&MockVerifier{getChainConfigFn: test.getLatestConfigFn})

parent := &types.Header{
Number: test.blockNumber,
GasLimit: test.parentGasLimit,
Expand Down Expand Up @@ -1595,7 +1472,7 @@ func TestBlockchain_WriteFullBlock(t *testing.T) {
Value: big.NewInt(1),
}

tx.ComputeHash()
tx.ComputeHash(1)
header.ComputeHash()
existingHeader.ComputeHash()
bc.currentHeader.Store(existingHeader)
Expand Down
8 changes: 7 additions & 1 deletion blockchain/storage/keyvalue.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,14 @@ func (s *KeyValueStorage) ReadBody(hash types.Hash) (*types.Body, error) {
return nil, err
}

// must read header because block number is needed in order to calculate each tx hash
header := &types.Header{}
if err := s.readRLP(HEADER, hash.Bytes(), header); err != nil {
return nil, err
}

for _, tx := range body.Transactions {
tx.ComputeHash()
tx.ComputeHash(header.Number)
}

return body, nil
Expand Down
Loading

0 comments on commit 7beeb38

Please sign in to comment.