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

Feat: generated code of validators sc sample #103

Merged
merged 1 commit into from
Aug 17, 2022

Conversation

DNK90
Copy link
Contributor

@DNK90 DNK90 commented Aug 17, 2022

No description provided.

@DNK90 DNK90 merged commit 2c80171 into consortium-v2 Aug 17, 2022
minh-bq added a commit that referenced this pull request Nov 9, 2022
* feat(consortiumV2): add consortium v2 block config (#91)

* [RON-156] feat(consortiumV2): implement Engine interface for Consortium wrapper (#90)

* feat(consortiumV2): implement Engine interface

just implement empty interface, function not yet

* fix(consortiumV2): remove consortium v2

* fix(consortiumV2): clean up consortium v2

* feat(consortiumV2): implement Consortium wrapper for v1

* feat(consortiumV2): implement SetGetSCValidatorsFn and SetGetFenixValidators

* feat(consortiumV2): implement Authorize

* fix(consortiumV2): Authorize params

* fix(consortiumV2): rename consortium to main for helping review

* [RON-156] feat(consortiumV2): implement Consortium v2 interface (#92)

* feat(consortiumV2): implement Consortium v2 interface

* feat(consortiumV2): implement logic for Consortium wrapper to call v2 or v1

* Add systemcontracts and function to trigger systemcontracts at forked block number (#93)

* [RON-161] feat: implement function to interacting with smart contract (#94)

* feat(consortiumV2): implement function to interacting with smart contract directly

* fix: missing new parameters

* fix: missing new parameters

* fix: invalid check consortium config nil

* fix: use signer hash instead of hash method

* chore: update FinalizeAndAssemble method in Engine interface (#96)

* [RON-165] Implement Snapshot methods (#98)

* feat: implement Snapshot methods

* feat: implement isMajorityFork method

* chore: implement isMajorityFork method

* fix: update loadSnapshot location

* fix: update store location

* chore: comment unused method

* chore: remove RecentForkHashes property

* feat: implement Consortium v2 verify methods (#99)

* feat: implement Consortium v2 verify method

* refactor: comment unused check in verifyCascadingFields

* refactor: use misc.VerifyGaslimit instead

* feat: implement Prepare method (#100)

* [RON-169] feat: implement Finalize and FinalizeAndAssemble methods (#101)

* feat: implement Finalize and FinalizeAndAssemble methods

* fix: remove init contract

* fix: remove unused import

* fix: missing import

* feat (dnk90): Add sample generated code of validators SC (#103)

* [DPoS] fix: call smart contract through backend instead of ethapi (#104)

* fix: call smart contract through backend instead of ethapi

* feat: Add BlockContext to simulated backend to prevent cycle import while using it in consensus package

* refactor: move contract to common

* fix: case sensitive

* fix: case sensitive

* fix: remove NewFaker

* fix: case sensitive

* refactor: call opts with BlockNumber

* fix: add missing header

* fix: assign systemTxs to ReceivedTxs

* feat (dnk90): Add balance to system address instead of coinbase, if block number is within consortiumV2 fork

* update (dnk90): use IsConsortiumV2 function instead

* refactor: impl Backend interface

* fix: spelling mistake

* refactor: eliminate magic number

* refactor: call update validators

* fix: checkpoint time

* fix: replace manual calculation by IsOnConsortiumV2

Co-authored-by: kien Dang <kien.15@gmail.com>

* Fix: add update validators to `finalize` method (#106)

* fix: Add updateValidators to `Finalize` method to make sure `updateValidators` transaction is processed in received sides

* fix: wrong validation when calling updateValidations

* fix: update validators generated code (#107)

- Add `addNode` function to support adding new nodes
- Change NewContractIntegrator param from `*ConsortiumBackend` to `bind.ContractBackend` interface to make it more flexible (we can adapt different backends lately)

* fix: Add missing signTx params when calling `consortium.Authorize` on miner (#108)

* Fix pointer issue validating end of v1 (#109)

* fix: worker starts before getValidatorsSC is set

* fix: call `SetGetSCValidatorsFn` instead of `SetGetFenixValidators` in `Consortium.SetGetSCValidatorsFn`

* fix: pointer issue when validating current block is end of v1 or not

* feat: implement Seal method (#111)

* [RON-202] feat: implement CalcDifficulty and Delay methods (#112)

* feat: implement Seal method

* feat: implement CalcDifficulty and Delay methods

* chore: add switch condition for Delay and Author

* Chore: Add sign tx fn to contract integrator (#110)

* chore: Add signFnTx to contract integrator, add deploy validators to generated validators

* fix: change FinanlizeAssemble that returns receipts to apply changing receipts length during processing system contracts

* fix: change gas limit

* fix: Add check recent to v1/verifySeal

* chore: Add contract_test which contains deploy and addNode codes

* fix: applying v2 contract from v1

* fix: Missing recents list in snapshot while switching v1 to v2 (#113)

* fix: Implement `PoSA` interface methods to main Consortium (#114)

* fix: Implement `PoSA` interface methods to main Consortium in order to get system contracts in v2

* chore: Remove unnecessary line

* nit: Remove redundant codes (#115)

- Remove redundant logs
- Remove systemcontracts package
- Move generated_contracts to consortium package

* fix(genesis): remove system contract (#117)

* feat: write unit tests for utils (#116)

* fix: reorgs and incorrect nonce in consortium-v2 (#118)

* fix: reorgs and incorrect nonce in consortium-v2

* chore: Remove getValidatorsFromLastCheckpoint, use snapshot instead

* chore: check signer in turn in `Seal` function instead of use `signerInTurn` function (#119)

* feat: integrate smart contract (#120)

* feat: integrate smart contract

* chore: remove dposStaking config

* chore: change generated contract from PascalCase to snake_case

* chore: remove validators contract

* chore: remove contract tests

* chore: add comment to avoid misleading

* Run FinalizeAndAssemble only on validator node (#122)

We accept that the system transactions will not be in the pending state so it is
unnecessary to call FinalizeAndAssemble in non-validator node. Move this call to
be called only on validator node

* fix: verify signer on v1 (#123)

* chore: fix missing signTxFn, clear outdated recents, check missing tx (#125)

* chore: fix missing signTxFn, clear outdate recents, check missing tx in state_processor

* chore: check tx.To instead of tx

* Make copy of block header when passing it to FinalizeAndAssemble (#126)

As default, an empty block without applying any transactions in transaction pool
is committed for sealing. Later, if there is no pending transactions in pool,
that empty block is inserted. Otherwise, another block is committed.

As we currently pass block header as a pointer to FinalizeAndAssemble, that block
header can be edited twice because it goes through FinalizeAndAssemble twice.
This leads to system transactions' gas used is accumulated twice, later results
in the mismatch between local and remote block's gas used calculation. We fix
this issue by make a copy of block header before passing it to
FinalizeAndAssemble.

* [RON-250] fix: backward compatible with v1 snapshot (#128)

* fix: load snapshot v1

* fix: store snapshot with the key consortium-

* chore(snapshot): remove check condition at block 0 and fork

* Choose the correct consortium version of ecrecover to be used on block header

* Log slashing on finalize only, add some comments on snapshot

Co-authored-by: Bui Quang Minh <minhbui@axieinfinity.com>

* [RON-251] fix: unknown ancestor (#129)

* fix: unknown ancestor

* chore: remove unused log

* fix: remove line on comment

* fix: remove unnecessary comment

* Remove unused variables and functions (#130)

* Remove unused variables and functions

* Remove deadcode when checking system transactions

* Call GetValidators on context of specific block instead of latest block (#131)

* feat: Implement log precompiled contract (#134)

* feat: Implement log precompiled contract

* chore: minify consortiumLog's abi

* chore: Add consortium precompiled contracts to list

* chore: only allow log in debug mode (--vmdebug or `DEBUG` env is set to "true")

* chore: Remove redundant function which get method from abi and input

* fix: update smart contract ABI (#132)

* fix: gas limit is not enough when call WrapUp (#135)

* fix: race condition while updating precompiles list (#136)

* Init precompile map before assigning elements (#137)

* feat: Implement `sortValidators` precompiled contract (#138)

* feat: Implement `sortValidators` precompiled contract

* fix: add caller to the contract, since caller is the actual caller instead of sender from transaction

* chore: add testcase which simulates a call from a user who trigger system contract to call `sort` precompiled contract

* fix: incorrect get validators function should be `getValidatorCandidates` instead

* [RON-264] docs(contract): add code comments (#139)

* docs(contract): add comments

* docs(contract): update comment for GetValidators

* fix: return error when failed to slash, wrap up (#133)

* feat: Implement verifyHeaders precompiled contract which detects double signing issue (#143)

* feat: Implement verifyHeaders precompiled contract which detects double signing issue

* chore: Remove unnecessary log init

* chore: simplify unit test, add chainId and change Number to big.Int

* chore: clean up code

* nit: comment to hacky (`unpack`) function

* chore: Add condition signer must equal to coinbase to prevent user uses fake signature

* [RON-274] docs(v2consortium): add code comments (#140)

* docs(v2consortium): add code comments

* docs(v2consortium): update Close comment

* docs(v2consortium): fix typo error

* [RON-276] docs(consortium-main): add code comment, remove unused constant (#141)

* docs(consortium-main): add code comment, remove unused ValidatorBytesLength constant

* docs(consortium-main): fix typo

* Append RONIN_PARAMS in case non-standard network id (#150)

* [RON-299] fix: update sortSC precompiled requirements (#151)

* fix: align precompiled requirements

* test: update TestConsortiumValidatorSorting_Run2

* test: update compiled code

* chore(precompiled): update consortiumValidatorSorting comments

* fix(entrypoint): failed to decode keystore key (#142)

* chore: add staking contract to chainconfig log (#144)

* [RON-312] feat(precompiled): impl update validator set by precompiled (#156)

* feat: impl update validator set by precompiled

* chore: rename filterCandidatesUnmaintained to pickCandidatesIsRunning

* fix: do not fill whitelist slots by others node

* fix: remove filter maintaining nodes

* test: update bytecode and abi of syncNewValidatorSet

* test(precompiled): update pickValidatorSet logic

create candidateMap maps address with isTrustedOrganizations to prevent the order changes

* fix: slice the candidates if the size is larger than newValidatorCount

* fix: change []bool isTrustedOrganizations to []*big.Int

* fix: out of bound waitingCandidates

* refactor(precompiled): update contract ABI

* Add devnet genesis file, change entrypoint.sh (#157)

Other networkids than 2020, 2021 gets the devnet.json as the genesisPath by
default. We delete all default params on testnet and devnet, all params must be
provided through RONIN_PARAMS variable.

* Always call SubmitBlockReward when producing block (#162)

Currently, validator only calls SubmitBlockReward when there is transaction
reward but the contract assumes this fuction is called in every block. Change
this to match smart contract assumption.

* Don't return error when system transactions revert (#163)

While testing, we observe a chain hang due to system transactions always revert
because a contract is out of token. We change this behavior to accept that
system transactions may revert and still produce block in these cases.

* Allocate a new bigInt instread of using Big0 (#168)

* Make a deep copy of environment before FinalizeAndAssemble (#166)

* Update generated contracts to the latest version (#170)

* Update to the latest contract ABI

* Add more information to debug log in applyMessage

* Change the length of epoch in consortium version 2 (#173)

The hardfork block number is assumed to be divisible to both old epoch and new
epoch

Co-authored-by: Linh Tran <110378492+linh-1@users.noreply.github.com>
Co-authored-by: Kien Dang <kien.15@gmail.com>
linh-1 added a commit that referenced this pull request Nov 14, 2022
* feat(consortiumV2): add consortium v2 block config (#91)

* [RON-156] feat(consortiumV2): implement Engine interface for Consortium wrapper (#90)

* feat(consortiumV2): implement Engine interface

just implement empty interface, function not yet

* fix(consortiumV2): remove consortium v2

* fix(consortiumV2): clean up consortium v2

* feat(consortiumV2): implement Consortium wrapper for v1

* feat(consortiumV2): implement SetGetSCValidatorsFn and SetGetFenixValidators

* feat(consortiumV2): implement Authorize

* fix(consortiumV2): Authorize params

* fix(consortiumV2): rename consortium to main for helping review

* [RON-156] feat(consortiumV2): implement Consortium v2 interface (#92)

* feat(consortiumV2): implement Consortium v2 interface

* feat(consortiumV2): implement logic for Consortium wrapper to call v2 or v1

* Add systemcontracts and function to trigger systemcontracts at forked block number (#93)

* [RON-161] feat: implement function to interacting with smart contract (#94)

* feat(consortiumV2): implement function to interacting with smart contract directly

* fix: missing new parameters

* fix: missing new parameters

* fix: invalid check consortium config nil

* fix: use signer hash instead of hash method

* chore: update FinalizeAndAssemble method in Engine interface (#96)

* [RON-165] Implement Snapshot methods (#98)

* feat: implement Snapshot methods

* feat: implement isMajorityFork method

* chore: implement isMajorityFork method

* fix: update loadSnapshot location

* fix: update store location

* chore: comment unused method

* chore: remove RecentForkHashes property

* feat: implement Consortium v2 verify methods (#99)

* feat: implement Consortium v2 verify method

* refactor: comment unused check in verifyCascadingFields

* refactor: use misc.VerifyGaslimit instead

* feat: implement Prepare method (#100)

* [RON-169] feat: implement Finalize and FinalizeAndAssemble methods (#101)

* feat: implement Finalize and FinalizeAndAssemble methods

* fix: remove init contract

* fix: remove unused import

* fix: missing import

* feat (dnk90): Add sample generated code of validators SC (#103)

* [DPoS] fix: call smart contract through backend instead of ethapi (#104)

* fix: call smart contract through backend instead of ethapi

* feat: Add BlockContext to simulated backend to prevent cycle import while using it in consensus package

* refactor: move contract to common

* fix: case sensitive

* fix: case sensitive

* fix: remove NewFaker

* fix: case sensitive

* refactor: call opts with BlockNumber

* fix: add missing header

* fix: assign systemTxs to ReceivedTxs

* feat (dnk90): Add balance to system address instead of coinbase, if block number is within consortiumV2 fork

* update (dnk90): use IsConsortiumV2 function instead

* refactor: impl Backend interface

* fix: spelling mistake

* refactor: eliminate magic number

* refactor: call update validators

* fix: checkpoint time

* fix: replace manual calculation by IsOnConsortiumV2

Co-authored-by: kien Dang <kien.15@gmail.com>

* Fix: add update validators to `finalize` method (#106)

* fix: Add updateValidators to `Finalize` method to make sure `updateValidators` transaction is processed in received sides

* fix: wrong validation when calling updateValidations

* fix: update validators generated code (#107)

- Add `addNode` function to support adding new nodes
- Change NewContractIntegrator param from `*ConsortiumBackend` to `bind.ContractBackend` interface to make it more flexible (we can adapt different backends lately)

* fix: Add missing signTx params when calling `consortium.Authorize` on miner (#108)

* Fix pointer issue validating end of v1 (#109)

* fix: worker starts before getValidatorsSC is set

* fix: call `SetGetSCValidatorsFn` instead of `SetGetFenixValidators` in `Consortium.SetGetSCValidatorsFn`

* fix: pointer issue when validating current block is end of v1 or not

* feat: implement Seal method (#111)

* [RON-202] feat: implement CalcDifficulty and Delay methods (#112)

* feat: implement Seal method

* feat: implement CalcDifficulty and Delay methods

* chore: add switch condition for Delay and Author

* Chore: Add sign tx fn to contract integrator (#110)

* chore: Add signFnTx to contract integrator, add deploy validators to generated validators

* fix: change FinanlizeAssemble that returns receipts to apply changing receipts length during processing system contracts

* fix: change gas limit

* fix: Add check recent to v1/verifySeal

* chore: Add contract_test which contains deploy and addNode codes

* fix: applying v2 contract from v1

* fix: Missing recents list in snapshot while switching v1 to v2 (#113)

* fix: Implement `PoSA` interface methods to main Consortium (#114)

* fix: Implement `PoSA` interface methods to main Consortium in order to get system contracts in v2

* chore: Remove unnecessary line

* nit: Remove redundant codes (#115)

- Remove redundant logs
- Remove systemcontracts package
- Move generated_contracts to consortium package

* fix(genesis): remove system contract (#117)

* feat: write unit tests for utils (#116)

* fix: reorgs and incorrect nonce in consortium-v2 (#118)

* fix: reorgs and incorrect nonce in consortium-v2

* chore: Remove getValidatorsFromLastCheckpoint, use snapshot instead

* chore: check signer in turn in `Seal` function instead of use `signerInTurn` function (#119)

* feat: integrate smart contract (#120)

* feat: integrate smart contract

* chore: remove dposStaking config

* chore: change generated contract from PascalCase to snake_case

* chore: remove validators contract

* chore: remove contract tests

* chore: add comment to avoid misleading

* Run FinalizeAndAssemble only on validator node (#122)

We accept that the system transactions will not be in the pending state so it is
unnecessary to call FinalizeAndAssemble in non-validator node. Move this call to
be called only on validator node

* fix: verify signer on v1 (#123)

* chore: fix missing signTxFn, clear outdated recents, check missing tx (#125)

* chore: fix missing signTxFn, clear outdate recents, check missing tx in state_processor

* chore: check tx.To instead of tx

* Make copy of block header when passing it to FinalizeAndAssemble (#126)

As default, an empty block without applying any transactions in transaction pool
is committed for sealing. Later, if there is no pending transactions in pool,
that empty block is inserted. Otherwise, another block is committed.

As we currently pass block header as a pointer to FinalizeAndAssemble, that block
header can be edited twice because it goes through FinalizeAndAssemble twice.
This leads to system transactions' gas used is accumulated twice, later results
in the mismatch between local and remote block's gas used calculation. We fix
this issue by make a copy of block header before passing it to
FinalizeAndAssemble.

* [RON-250] fix: backward compatible with v1 snapshot (#128)

* fix: load snapshot v1

* fix: store snapshot with the key consortium-

* chore(snapshot): remove check condition at block 0 and fork

* Choose the correct consortium version of ecrecover to be used on block header

* Log slashing on finalize only, add some comments on snapshot

Co-authored-by: Bui Quang Minh <minhbui@axieinfinity.com>

* [RON-251] fix: unknown ancestor (#129)

* fix: unknown ancestor

* chore: remove unused log

* fix: remove line on comment

* fix: remove unnecessary comment

* Remove unused variables and functions (#130)

* Remove unused variables and functions

* Remove deadcode when checking system transactions

* Call GetValidators on context of specific block instead of latest block (#131)

* feat: Implement log precompiled contract (#134)

* feat: Implement log precompiled contract

* chore: minify consortiumLog's abi

* chore: Add consortium precompiled contracts to list

* chore: only allow log in debug mode (--vmdebug or `DEBUG` env is set to "true")

* chore: Remove redundant function which get method from abi and input

* fix: update smart contract ABI (#132)

* fix: gas limit is not enough when call WrapUp (#135)

* fix: race condition while updating precompiles list (#136)

* Init precompile map before assigning elements (#137)

* feat: Implement `sortValidators` precompiled contract (#138)

* feat: Implement `sortValidators` precompiled contract

* fix: add caller to the contract, since caller is the actual caller instead of sender from transaction

* chore: add testcase which simulates a call from a user who trigger system contract to call `sort` precompiled contract

* fix: incorrect get validators function should be `getValidatorCandidates` instead

* [RON-264] docs(contract): add code comments (#139)

* docs(contract): add comments

* docs(contract): update comment for GetValidators

* fix: return error when failed to slash, wrap up (#133)

* feat: Implement verifyHeaders precompiled contract which detects double signing issue (#143)

* feat: Implement verifyHeaders precompiled contract which detects double signing issue

* chore: Remove unnecessary log init

* chore: simplify unit test, add chainId and change Number to big.Int

* chore: clean up code

* nit: comment to hacky (`unpack`) function

* chore: Add condition signer must equal to coinbase to prevent user uses fake signature

* [RON-274] docs(v2consortium): add code comments (#140)

* docs(v2consortium): add code comments

* docs(v2consortium): update Close comment

* docs(v2consortium): fix typo error

* [RON-276] docs(consortium-main): add code comment, remove unused constant (#141)

* docs(consortium-main): add code comment, remove unused ValidatorBytesLength constant

* docs(consortium-main): fix typo

* Append RONIN_PARAMS in case non-standard network id (#150)

* [RON-299] fix: update sortSC precompiled requirements (#151)

* fix: align precompiled requirements

* test: update TestConsortiumValidatorSorting_Run2

* test: update compiled code

* chore(precompiled): update consortiumValidatorSorting comments

* fix(entrypoint): failed to decode keystore key (#142)

* chore: add staking contract to chainconfig log (#144)

* docs(README): update overview and contributions

Co-authored-by: Kien Dang <kien.15@gmail.com>
Co-authored-by: minh-bq <97180373+minh-bq@users.noreply.github.com>
Co-authored-by: Bui Quang Minh <minhbui@axieinfinity.com>
@DNK90 DNK90 deleted the feat/generated_code_of_validators_SC_sample branch November 22, 2022 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant