Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge consortium v2 to master #174

Merged
merged 58 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
01e1f75
feat(consortiumV2): add consortium v2 block config (#91)
linh-1 Aug 10, 2022
11fca7e
[RON-156] feat(consortiumV2): implement Engine interface for Consorti…
linh-1 Aug 11, 2022
5955b14
[RON-156] feat(consortiumV2): implement Consortium v2 interface (#92)
linh-1 Aug 11, 2022
06ad181
Add systemcontracts and function to trigger systemcontracts at forked…
DNK90 Aug 11, 2022
1c7e835
[RON-161] feat: implement function to interacting with smart contract…
linh-1 Aug 12, 2022
6eb999a
chore: update FinalizeAndAssemble method in Engine interface (#96)
linh-1 Aug 15, 2022
346145b
[RON-165] Implement Snapshot methods (#98)
linh-1 Aug 16, 2022
d1aab4f
feat: implement Consortium v2 verify methods (#99)
linh-1 Aug 16, 2022
e4e3dd6
feat: implement Prepare method (#100)
linh-1 Aug 17, 2022
225b7c6
[RON-169] feat: implement Finalize and FinalizeAndAssemble methods (#…
linh-1 Aug 17, 2022
c5c4230
feat (dnk90): Add sample generated code of validators SC (#103)
DNK90 Aug 17, 2022
90bd08f
[DPoS] fix: call smart contract through backend instead of ethapi (#104)
linh-1 Aug 19, 2022
55224de
Fix: add update validators to `finalize` method (#106)
DNK90 Aug 21, 2022
14a3c99
fix: update validators generated code (#107)
DNK90 Aug 21, 2022
8deb4bc
fix: Add missing signTx params when calling `consortium.Authorize` on…
DNK90 Aug 21, 2022
7fff33e
Fix pointer issue validating end of v1 (#109)
DNK90 Aug 22, 2022
64b458a
feat: implement Seal method (#111)
linh-1 Aug 23, 2022
3d8a3e6
[RON-202] feat: implement CalcDifficulty and Delay methods (#112)
linh-1 Aug 23, 2022
27bdc56
Chore: Add sign tx fn to contract integrator (#110)
DNK90 Aug 23, 2022
ed3124a
fix: Missing recents list in snapshot while switching v1 to v2 (#113)
DNK90 Aug 25, 2022
c9e7442
fix: Implement `PoSA` interface methods to main Consortium (#114)
DNK90 Aug 25, 2022
9d237ec
nit: Remove redundant codes (#115)
DNK90 Aug 26, 2022
0f4509f
fix(genesis): remove system contract (#117)
linh-1 Sep 1, 2022
5f0801e
feat: write unit tests for utils (#116)
linh-1 Sep 1, 2022
50a99ff
fix: reorgs and incorrect nonce in consortium-v2 (#118)
DNK90 Sep 5, 2022
8964d54
chore: check signer in turn in `Seal` function instead of use `signer…
DNK90 Sep 6, 2022
dd1df32
feat: integrate smart contract (#120)
linh-1 Sep 8, 2022
28cb44c
Run FinalizeAndAssemble only on validator node (#122)
minh-bq Sep 13, 2022
cb5bb80
fix: verify signer on v1 (#123)
linh-1 Sep 13, 2022
2a842d5
chore: fix missing signTxFn, clear outdated recents, check missing tx…
linh-1 Sep 16, 2022
6c5f58a
Make copy of block header when passing it to FinalizeAndAssemble (#126)
minh-bq Sep 16, 2022
7ecaa85
[RON-250] fix: backward compatible with v1 snapshot (#128)
linh-1 Sep 23, 2022
0c42f48
[RON-251] fix: unknown ancestor (#129)
linh-1 Sep 23, 2022
3d3434c
Remove unused variables and functions (#130)
minh-bq Sep 23, 2022
1a29fa1
Call GetValidators on context of specific block instead of latest blo…
minh-bq Sep 23, 2022
e44fccd
feat: Implement log precompiled contract (#134)
DNK90 Sep 29, 2022
743fe84
fix: update smart contract ABI (#132)
linh-1 Sep 29, 2022
0265118
fix: gas limit is not enough when call WrapUp (#135)
linh-1 Sep 29, 2022
40a202b
fix: race condition while updating precompiles list (#136)
DNK90 Sep 29, 2022
7d206ec
Init precompile map before assigning elements (#137)
minh-bq Sep 29, 2022
002c23a
feat: Implement `sortValidators` precompiled contract (#138)
DNK90 Oct 3, 2022
aca43aa
[RON-264] docs(contract): add code comments (#139)
linh-1 Oct 3, 2022
9ef06ad
fix: return error when failed to slash, wrap up (#133)
minh-bq Oct 3, 2022
9d5b34c
feat: Implement verifyHeaders precompiled contract which detects doub…
DNK90 Oct 7, 2022
a655772
[RON-274] docs(v2consortium): add code comments (#140)
linh-1 Oct 12, 2022
f43017d
[RON-276] docs(consortium-main): add code comment, remove unused cons…
linh-1 Oct 12, 2022
4fcf48a
Append RONIN_PARAMS in case non-standard network id (#150)
minh-bq Oct 13, 2022
949b6c0
[RON-299] fix: update sortSC precompiled requirements (#151)
linh-1 Oct 14, 2022
5a4205b
fix(entrypoint): failed to decode keystore key (#142)
linh-1 Oct 14, 2022
3fdb601
chore: add staking contract to chainconfig log (#144)
minh-bq Oct 14, 2022
d2d34e9
[RON-312] feat(precompiled): impl update validator set by precompiled…
linh-1 Oct 27, 2022
98ee7b3
Add devnet genesis file, change entrypoint.sh (#157)
minh-bq Nov 1, 2022
3015d5a
Always call SubmitBlockReward when producing block (#162)
minh-bq Nov 2, 2022
31d78e8
Don't return error when system transactions revert (#163)
minh-bq Nov 2, 2022
db67dbb
Allocate a new bigInt instread of using Big0 (#168)
minh-bq Nov 4, 2022
e6bafc9
Make a deep copy of environment before FinalizeAndAssemble (#166)
minh-bq Nov 4, 2022
1a8896a
Update generated contracts to the latest version (#170)
minh-bq Nov 7, 2022
af69bf5
Change the length of epoch in consortium version 2 (#173)
minh-bq Nov 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@
GOBIN = ./build/bin
GO ?= latest
GORUN = go run
RONIN_CONTRACTS_PATH = ../ronin-dpos-contracts
RONIN_CONTRACTS_OUTPUT_PATH = ./tmp/contracts
GEN_CONTRACTS_OUTPUT_PATH = ./consensus/consortium/generated_contracts

generate-contract:
@echo "Generating"
solc --abi --bin $(RONIN_CONTRACTS_PATH)/contracts/ronin/staking/Staking.sol -o $(RONIN_CONTRACTS_OUTPUT_PATH)/staking --include-path $(RONIN_CONTRACTS_PATH)/node_modules/ --base-path $(RONIN_CONTRACTS_PATH) --overwrite --optimize
abigen --abi $(RONIN_CONTRACTS_OUTPUT_PATH)/staking/Staking.abi --bin $(RONIN_CONTRACTS_OUTPUT_PATH)/staking/Staking.bin --pkg staking --out $(GEN_CONTRACTS_OUTPUT_PATH)/staking/staking.go

solc --abi --bin $(RONIN_CONTRACTS_PATH)/contracts/ronin/validator/RoninValidatorSet.sol -o $(RONIN_CONTRACTS_OUTPUT_PATH)/validator --include-path $(RONIN_CONTRACTS_PATH)/node_modules/ --base-path $(RONIN_CONTRACTS_PATH) --overwrite --optimize
abigen --abi $(RONIN_CONTRACTS_OUTPUT_PATH)/validator/RoninValidatorSet.abi --bin $(RONIN_CONTRACTS_OUTPUT_PATH)/validator/RoninValidatorSet.bin --pkg roninValidatorSet --out $(GEN_CONTRACTS_OUTPUT_PATH)/ronin_validator_set/ronin_validator_set.go

solc --abi --bin $(RONIN_CONTRACTS_PATH)/contracts/ronin/SlashIndicator.sol -o $(RONIN_CONTRACTS_OUTPUT_PATH)/slashing --include-path $(RONIN_CONTRACTS_PATH)/node_modules/ --base-path $(RONIN_CONTRACTS_PATH) --overwrite --optimize
abigen --abi $(RONIN_CONTRACTS_OUTPUT_PATH)/slashing/SlashIndicator.abi --bin $(RONIN_CONTRACTS_OUTPUT_PATH)/slashing/SlashIndicator.bin --pkg slashIndicator --out $(GEN_CONTRACTS_OUTPUT_PATH)/slash_indicator/slash_indicator.go

ronin:
$(GORUN) build/ci.go install ./cmd/ronin
Expand Down
1 change: 1 addition & 0 deletions accounts/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const (
MimetypeDataWithValidator = "data/validator"
MimetypeTypedData = "data/typed"
MimetypeClique = "application/x-clique-header"
MimetypeConsortium = "application/x-clique-header"
MimetypeTextPlain = "text/plain"
)

Expand Down
2 changes: 2 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,8 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
if ctx.GlobalIsSet(VMEnableDebugFlag.Name) {
// TODO(fjl): force-enable this in --dev mode
cfg.EnablePreimageRecording = ctx.GlobalBool(VMEnableDebugFlag.Name)
// set debug environment to true
os.Setenv("DEBUG", "true")
}

if ctx.GlobalIsSet(RPCGlobalGasCapFlag.Name) {
Expand Down
16 changes: 12 additions & 4 deletions consensus/clique/clique.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,20 +562,24 @@ func (c *Clique) Prepare(chain consensus.ChainHeaderReader, header *types.Header

// Finalize implements consensus.Engine, ensuring no uncles are set, nor block
// rewards given.
func (c *Clique) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header) {
func (c *Clique) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs *[]*types.Transaction,
uncles []*types.Header, receipts *[]*types.Receipt, systemTxs *[]*types.Transaction, usedGas *uint64) error {
// No block rewards in PoA, so the state remains as is and uncles are dropped
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
header.UncleHash = types.CalcUncleHash(nil)

return nil
}

// FinalizeAndAssemble implements consensus.Engine, ensuring no uncles are set,
// nor block rewards given, and returns the final block.
func (c *Clique) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) {
func (c *Clique) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction,
uncles []*types.Header, receipts []*types.Receipt) (*types.Block, []*types.Receipt, error) {
// Finalize block
c.Finalize(chain, header, state, txs, uncles)
c.Finalize(chain, header, state, &txs, uncles, nil, nil, nil)

// Assemble and return the final block for sealing
return types.NewBlock(header, txs, nil, receipts, trie.NewStackTrie(nil)), nil
return types.NewBlock(header, txs, nil, receipts, trie.NewStackTrie(nil)), receipts, nil
}

// Authorize injects a private key into the consensus engine to mint new blocks
Expand All @@ -588,6 +592,10 @@ func (c *Clique) Authorize(signer common.Address, signFn SignerFn) {
c.signFn = signFn
}

func (c *Clique) Delay(chain consensus.ChainReader, header *types.Header) *time.Duration {
return nil
}

// Seal implements consensus.Engine, attempting to create a sealed block using
// the local signing credentials.
func (c *Clique) Seal(chain consensus.ChainHeaderReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error {
Expand Down
24 changes: 20 additions & 4 deletions consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
package consensus

import (
"github.com/ethereum/go-ethereum/ethdb"
"math/big"
"time"

"github.com/ethereum/go-ethereum/ethdb"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state"
Expand All @@ -28,6 +30,10 @@ import (
"github.com/ethereum/go-ethereum/rpc"
)

var (
SystemAddress = common.HexToAddress("0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE")
)

// ChainHeaderReader defines a small collection of methods needed to access the local
// blockchain during header verification.
type ChainHeaderReader interface {
Expand Down Expand Up @@ -93,16 +99,16 @@ type Engine interface {
//
// Note: The block header and state database might be updated to reflect any
// consensus rules that happen at finalization (e.g. block rewards).
Finalize(chain ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction,
uncles []*types.Header)
Finalize(chain ChainHeaderReader, header *types.Header, state *state.StateDB, txs *[]*types.Transaction,
uncles []*types.Header, receipts *[]*types.Receipt, systemTxs *[]*types.Transaction, usedGas *uint64) error

// FinalizeAndAssemble runs any post-transaction state modifications (e.g. block
// rewards) and assembles the final block.
//
// Note: The block header and state database might be updated to reflect any
// consensus rules that happen at finalization (e.g. block rewards).
FinalizeAndAssemble(chain ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction,
uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error)
uncles []*types.Header, receipts []*types.Receipt) (*types.Block, []*types.Receipt, error)

// Seal generates a new sealing request for the given input block and pushes
// the result into the given channel.
Expand All @@ -121,6 +127,9 @@ type Engine interface {
// APIs returns the RPC APIs this consensus engine provides.
APIs(chain ChainHeaderReader) []rpc.API

// Delay returns the max duration the miner can commit txs
Delay(chain ChainReader, header *types.Header) *time.Duration

// Close terminates any background threads maintained by the consensus engine.
Close() error
}
Expand All @@ -132,3 +141,10 @@ type PoW interface {
// Hashrate returns the current mining hashrate of a PoW consensus engine.
Hashrate() float64
}

type PoSA interface {
Engine

IsSystemTransaction(tx *types.Transaction, header *types.Header) (bool, error)
IsSystemContract(to *common.Address) bool
}
53 changes: 53 additions & 0 deletions consensus/consortium/common/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package common

import (
"errors"
"github.com/ethereum/go-ethereum/crypto"
)

const (
ExtraSeal = crypto.SignatureLength // Fixed number of extra-data suffix bytes reserved for signer seal
)

var (
// ErrMissingSignature is returned if a block's extra-data section doesn't seem
// to contain a 65 byte secp256k1 signature.
ErrMissingSignature = errors.New("extra-data 65 byte signature suffix missing")

// ErrUnknownBlock is returned when the list of signers is requested for a block
// that is not part of the local blockchain.
ErrUnknownBlock = errors.New("unknown block")

// ErrMissingVanity is returned if a block's extra-data section is shorter than
// 32 bytes, which is required to store the signer vanity.
ErrMissingVanity = errors.New("extra-data 32 byte vanity prefix missing")

// ErrExtraValidators is returned if non-sprint-end block contain validator data in
// their extra-data fields.
ErrExtraValidators = errors.New("non-sprint-end block contains extra validator list")

// ErrInvalidSpanValidators is returned if a block contains an
// invalid list of validators (i.e. non divisible by 20 bytes).
ErrInvalidSpanValidators = errors.New("invalid validator list on sprint end block")

// ErrInvalidMixDigest is returned if a block's mix digest is non-zero.
ErrInvalidMixDigest = errors.New("non-zero mix digest")

// ErrInvalidUncleHash is returned if a block contains an non-empty uncle list.
ErrInvalidUncleHash = errors.New("non empty uncle hash")

// ErrInvalidDifficulty is returned if the difficulty of a block neither 1 or 2.
ErrInvalidDifficulty = errors.New("invalid difficulty")

// ErrInvalidCheckpointSigners is returned if a checkpoint block contains an
// invalid list of signers (i.e. non divisible by 20 bytes).
ErrInvalidCheckpointSigners = errors.New("invalid signer list on checkpoint block")

// ErrRecentlySigned is returned if a header is signed by an authorized entity
// that already signed a header recently, thus is temporarily not allowed to.
ErrRecentlySigned = errors.New("signed recently, must wait for others")

// ErrWrongDifficulty is returned if the difficulty of a block doesn't match the
// turn of the signer.
ErrWrongDifficulty = errors.New("wrong difficulty")
)
24 changes: 24 additions & 0 deletions consensus/consortium/common/context.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package common

import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/core/types"
)

// ChainContext supports retrieving headers and consensus parameters from the
// current blockchain to be used during transaction processing.
type ChainContext struct {
Chain consensus.ChainHeaderReader
Consortium consensus.Engine
}

// Engine retrieves the chain's consensus engine.
func (c ChainContext) Engine() consensus.Engine {
return c.Consortium
}

// GetHeader returns the hash corresponding to their hash.
func (c ChainContext) GetHeader(hash common.Hash, number uint64) *types.Header {
return c.Chain.GetHeader(hash, number)
}
Loading