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

Move PolyBFT to Edge #774

Merged
merged 100 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
9f01ed5
Initial commit
Nemanja0x Sep 29, 2022
483d7ed
some fixes
igorcrevar Sep 29, 2022
ed4c4d7
system_state after rebase
igorcrevar Sep 29, 2022
f5bac88
remove vendors folder
igorcrevar Sep 29, 2022
119ef2f
Add bls signer library.
0xSasaPrsic Sep 29, 2022
6ef6667
Event tracker fixed and fms - logger packegs
Nemanja0x Sep 29, 2022
2c466fd
consensus_runtime fixed
Nemanja0x Sep 29, 2022
362aee9
block-builder
igorcrevar Sep 29, 2022
b14cf17
Remove duplicate method.
0xSasaPrsic Sep 29, 2022
48b179c
Add validators snapshot.
0xSasaPrsic Sep 29, 2022
658f821
v3-contracts submodule + block_builder small fixes
igorcrevar Sep 29, 2022
4556e09
small changes
igorcrevar Sep 29, 2022
39a33f0
contract deploy
igorcrevar Sep 29, 2022
d69b908
contract deploy
igorcrevar Sep 29, 2022
d4f56d4
block builder fixed
Nemanja0x Sep 30, 2022
44713ef
Make state provider great again (hopefully)
Stefan-Ethernal Sep 30, 2022
7bc8713
Initial polybft migration code.
0xSasaPrsic Sep 30, 2022
168bf82
Trasition added
Nemanja0x Sep 30, 2022
d68816c
account=bls+ecdsa
igorcrevar Sep 30, 2022
2e8da0c
Update blockchain wrapper
Stefan-Ethernal Sep 30, 2022
7571d55
Linters fix
Stefan-Ethernal Sep 30, 2022
85f85ff
key fixed
Nemanja0x Oct 2, 2022
61f25a7
key fixed for real
Nemanja0x Oct 2, 2022
127e455
Factoru, Init, Start, Close, VerifyFeader on Polybft
Nemanja0x Oct 2, 2022
2bf3ff7
Remove InsertBlock from polybft
Nemanja0x Oct 2, 2022
09ec57b
Cleanups and draft idea for polybft population
Stefan-Ethernal Oct 3, 2022
3869e8e
Add transport message proto definition and subscription.
0xSasaPrsic Oct 3, 2022
6cb583e
fix cache
igorcrevar Oct 3, 2022
c6771b2
fix lint errors in signer and wallet
igorcrevar Oct 3, 2022
2b4f677
Init Genesis
igorcrevar Oct 3, 2022
a303343
linter...
igorcrevar Oct 3, 2022
84742fc
small change
igorcrevar Oct 3, 2022
6b57a8a
Set coinbase properly in blockchain wrapper
Stefan-Ethernal Oct 3, 2022
19e15ca
ProcessBlock and BuildBlock fixed
Nemanja0x Oct 3, 2022
824cce3
Define default values for Polybft config, simplify deployContracts
Stefan-Ethernal Oct 3, 2022
66ca172
start syncing
Nemanja0x Oct 3, 2022
f5d9103
getLatestAfterSync
Nemanja0x Oct 3, 2022
b2fd576
GetValidators implemented
Stefan-Ethernal Oct 4, 2022
1627b0c
Polybft consensus configuration initial approach
Stefan-Ethernal Oct 4, 2022
86bf55d
Add pbft genesis command
Stefan-Ethernal Oct 4, 2022
96e4f56
Add polybft hash function.
0xSasaPrsic Oct 4, 2022
f624c48
SubscribeEvents added to blockchain wrapper
Nemanja0x Oct 4, 2022
6463ce7
wait for sync - initial logic
Nemanja0x Oct 4, 2022
7dcd40f
isSynced function added
Stefan-Ethernal Oct 4, 2022
49eb270
Setup polybft data directory
Stefan-Ethernal Oct 4, 2022
28eb649
Add logger and tidy.
0xSasaPrsic Oct 4, 2022
053f803
Replace licensed code.
0xSasaPrsic Oct 4, 2022
07ab165
Flag active validator
Stefan-Ethernal Oct 4, 2022
4bcf151
Lint fixes
Stefan-Ethernal Oct 4, 2022
2ec8b89
Prevent non active validator participate in consensus
Stefan-Ethernal Oct 4, 2022
6c838a9
Update protoc version.
0xSasaPrsic Oct 4, 2022
07faccf
genesis-polybft
igorcrevar Oct 4, 2022
44ad7bc
Bump latest version of protoc.
0xSasaPrsic Oct 4, 2022
d556755
Change logical condition in isSynced
Stefan-Ethernal Oct 4, 2022
b08f651
generate secrets polybft
igorcrevar Oct 4, 2022
bfd4148
two fixes
igorcrevar Oct 4, 2022
3999dda
Fix isSynced add node_modules to gitignore
Stefan-Ethernal Oct 5, 2022
394d624
Deserialize polybft config
Stefan-Ethernal Oct 5, 2022
c43fca5
Populate genesis validator set delta
Stefan-Ethernal Oct 5, 2022
76ba046
fixes
igorcrevar Oct 5, 2022
d9a3658
Set block hashing callback in polybft
Stefan-Ethernal Oct 5, 2022
7c0f2cf
extra fix, header hash fix, liner fixes
igorcrevar Oct 5, 2022
dc0bb8c
Migrate one part of the unit tests for extra.go
0xSasaPrsic Oct 5, 2022
810272b
Add more tests for header extra.
0xSasaPrsic Oct 5, 2022
11624aa
stateProvider call
igorcrevar Oct 5, 2022
7f2f631
State provider fix, account test fix
igorcrevar Oct 5, 2022
02d2457
Move pbft topic creation.
0xSasaPrsic Oct 6, 2022
cd0629c
Empty genesis post hook added
Nemanja0x Oct 6, 2022
7d658e5
sc deploying into genesis
igorcrevar Oct 6, 2022
74176e0
InitValidatorSet method instead of constructor
igorcrevar Oct 6, 2022
67bf0d2
Fixing transitions by passing correct state root hash
Stefan-Ethernal Oct 7, 2022
ad77bc8
Remove variable shadowing.
0xSasaPrsic Oct 7, 2022
cdc0bda
some changes
igorcrevar Oct 7, 2022
c8b4ad7
Encode init validators data for SC
Stefan-Ethernal Oct 7, 2022
d2201b4
Make querying validator SC great again
Stefan-Ethernal Oct 7, 2022
f8a27cc
Return transition from block builder
Stefan-Ethernal Oct 7, 2022
7de4499
Linter fixes
Stefan-Ethernal Oct 10, 2022
1712358
Remove Receipts from Block Builder
Nemanja0x Oct 10, 2022
e926ca4
Adapt configuration to the new GH workflow
Stefan-Ethernal Oct 10, 2022
209fd4f
Address some of the TODOs
Stefan-Ethernal Oct 10, 2022
3c8182b
Uncomment Test_PrivateMarshal
Stefan-Ethernal Oct 10, 2022
eff10fd
Removed duplicate createValidatorSetDelta
Nemanja0x Oct 10, 2022
9ed8b3b
Unexport createValidatorSetDelta
Stefan-Ethernal Oct 10, 2022
6ce2cae
Merge genesis commands
Oct 11, 2022
7515a88
Linter fix
Stefan-Ethernal Oct 11, 2022
b79ddbd
Properly handle non PolyBFT consensus
Oct 11, 2022
654491a
Exclude only PolyBFT
Oct 11, 2022
f1b0b3c
Parameters descirptions fixed
Nemanja0x Oct 12, 2022
62a4f8c
ethgo.HexToAddress -> types.StringToAddress
Nemanja0x Oct 12, 2022
b54d4ec
pr fixes
igorcrevar Oct 12, 2022
989da00
pr fixes again
igorcrevar Oct 12, 2022
00883a1
pr fix
igorcrevar Oct 12, 2022
6047c44
pr fix
igorcrevar Oct 12, 2022
3e87d3e
pr fix
igorcrevar Oct 12, 2022
677d716
remove some logs
igorcrevar Oct 12, 2022
224744f
pr fix
igorcrevar Oct 12, 2022
604c2ff
small change
igorcrevar Oct 12, 2022
e27dca1
Move polybft-secrets command to command package
Oct 12, 2022
7e0e098
Merge branch 'feature/EVM_44_Move_Polybft_to_Edge' of github.com:0xPo…
Oct 12, 2022
7998164
Exit early on PolyBFT
Oct 12, 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
2 changes: 2 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
uses: actions/setup-go@v3
with:
go-version: 1.18.x
- name: Compile v3 contracts
run: make compile-v3-contracts
- name: Run tests
run: make test-e2e
- name: Archive test logs
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3

- name: Compile v3 contracts
run: make compile-v3-contracts

Stefan-Ethernal marked this conversation as resolved.
Show resolved Hide resolved
- name: Lint
uses: golangci/golangci-lint-action@v3
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ jobs:
with:
submodules: recursive

- name: Compile v3 contracts
run: make compile-v3-contracts

- name: Run Go Test
run: go test -coverprofile coverage.out -timeout 20m `go list ./... | grep -v e2e`

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ main

# exclude build folder
artifacts
consensus/polybft/polybftcontracts/cache
consensus/polybft/polybftcontracts/package-lock.json
node_modules

# Log files
*.log
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "tests/tests"]
path = tests/tests
url = https://github.com/ethereum/tests.git
[submodule "v3-contracts"]
path = v3-contracts
url = https://github.com/maticnetwork/v3-contracts.git
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ bindata:
.PHONY: protoc
protoc:
protoc --go_out=. --go-grpc_out=. ./server/proto/*.proto
protoc --go_out=. --go-grpc_out=. ./protocol/proto/*.proto
#protoc --go_out=. --go-grpc_out=. ./protocol/proto/*.proto
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this leftover?
Remove it if it's unused

protoc --go_out=. --go-grpc_out=. ./network/proto/*.proto
protoc --go_out=. --go-grpc_out=. ./txpool/proto/*.proto
protoc --go_out=. --go-grpc_out=. ./consensus/ibft/**/*.proto
protoc --go_out=. --go-grpc_out=. ./consensus/polybft/**/*.proto

.PHONY: build
build:
Expand Down Expand Up @@ -57,3 +58,7 @@ run-local:
stop-local:
docker-compose -f ./docker/local/docker-compose.yml stop

.PHONY: compile-v3-contracts
compile-v3-contracts:
cd consensus/polybft/polybftcontracts && npm install && npm run compile

50 changes: 46 additions & 4 deletions command/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ func GetCommand() *cobra.Command {
setFlags(genesisCmd)
setLegacyFlags(genesisCmd)

helper.SetRequiredFlags(genesisCmd, params.getRequiredFlags())

Comment on lines -28 to -29
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this moved to runPreRun?

Please move it back, as all methods that have required flags initialize them in the standard GetCommand method

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the correct place in init flow, in this case, different required flags are required depending on the selected consensus, at this point of the execution if p.isIBFTConsensus() or p.consensusRaw is set to its default value.

Conditionally required flags should be setup in the PreRunE, see for example spf13/cobra#1595 (comment)

genesisCmd.AddCommand(
// genesis predeploy
predeploy.GetCommand(),
Expand Down Expand Up @@ -148,6 +146,40 @@ func setFlags(cmd *cobra.Command) {
"the maximum number of validators in the validator set for PoS",
)
}

// PolyBFT
{
cmd.Flags().IntVar(
&params.validatorSetSize,
validatorSetSizeFlag,
defaultValidatorSetSize,
"the total number of validators",
)
cmd.Flags().StringVar(
&params.polyBftValidatorPrefixPath,
polyBftValidatorPrefixPathFlag,
defaultPolyBftValidatorPrefixPath,
"prefix path for polybft validator folder directory",
)
cmd.Flags().Uint64Var(
&params.sprintSize,
sprintSizeFlag,
defaultSprintSize,
"the number of block included into a sprint",
)
cmd.Flags().DurationVar(
&params.blockTime,
blockTimeFlag,
defaultBlockTime,
"the predefined period which determines block creation frequency",
)
cmd.Flags().StringArrayVar(
&params.validators,
validatorsFlag,
[]string{},
"validators defined by user throughout a parameter (format: <address>:<blskey>)",
)
}
}

// setLegacyFlags sets the legacy flags to preserve backwards compatibility
Expand All @@ -164,19 +196,29 @@ func setLegacyFlags(cmd *cobra.Command) {
_ = cmd.Flags().MarkHidden(chainIDFlagLEGACY)
}

func runPreRun(_ *cobra.Command, _ []string) error {
func runPreRun(cmd *cobra.Command, _ []string) error {
if err := params.validateFlags(); err != nil {
return err
}

helper.SetRequiredFlags(cmd, params.getRequiredFlags())

return params.initRawParams()
}

func runCommand(cmd *cobra.Command, _ []string) {
outputter := command.InitializeOutputter(cmd)
defer outputter.WriteOutput()

if err := params.generateGenesis(); err != nil {
var err error

if params.isPolyBFTConsensus() {
err = params.generatePolyBftGenesis()
} else {
err = params.generateGenesis()
}

if err != nil {
outputter.SetError(err)

return
Expand Down
27 changes: 24 additions & 3 deletions command/genesis/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package genesis
import (
"errors"
"fmt"
"time"

"github.com/0xPolygon/polygon-edge/chain"
"github.com/0xPolygon/polygon-edge/command"
Expand Down Expand Up @@ -72,6 +73,14 @@ type genesisParams struct {
consensusEngineConfig map[string]interface{}

genesisConfig *chain.Chain

// PolyBFT
validatorSetSize int
sprintSize uint64
blockTime time.Duration
validators []string

polyBftValidatorPrefixPath string
}

func (p *genesisParams) validateFlags() error {
Expand All @@ -93,7 +102,7 @@ func (p *genesisParams) validateFlags() error {
}

// Check that the epoch size is correct
if p.epochSize < 2 && server.ConsensusType(p.consensusRaw) == server.IBFTConsensus {
if p.epochSize < 2 && (p.isIBFTConsensus() || p.isPolyBFTConsensus()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not extract this second part of the conditional into a separate method like hasEpochs, or something similar?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not usually a fan of moving oneliners to 4 lines methods, specially if they are only used once.

// Epoch size must be greater than 1, so new transactions have a chance to be added to a block.
// Otherwise, every block would be an endblock (meaning it will not have any transactions).
// Check is placed here to avoid additional parsing if epochSize < 2
Expand All @@ -112,6 +121,10 @@ func (p *genesisParams) isIBFTConsensus() bool {
return server.ConsensusType(p.consensusRaw) == server.IBFTConsensus
}

func (p *genesisParams) isPolyBFTConsensus() bool {
return server.ConsensusType(p.consensusRaw) == server.PolyBFTConsensus
}

func (p *genesisParams) areValidatorsSetManually() bool {
return len(p.ibftValidatorsRaw) != 0
}
Expand All @@ -121,14 +134,22 @@ func (p *genesisParams) areValidatorsSetByPrefix() bool {
}

func (p *genesisParams) getRequiredFlags() []string {
return []string{
command.BootnodeFlag,
if p.isIBFTConsensus() {
return []string{
command.BootnodeFlag,
}
}

return []string{}
}

func (p *genesisParams) initRawParams() error {
p.consensus = server.ConsensusType(p.consensusRaw)

if p.consensus == server.PolyBFTConsensus {
return nil
}

if err := p.initIBFTValidatorType(); err != nil {
return err
}
Expand Down
Loading