|
|
|
package consensus
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/big"
|
|
|
|
"sync/atomic"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/harmony-one/harmony/core"
|
|
|
|
"github.com/harmony-one/harmony/core/types"
|
|
|
|
"github.com/harmony-one/harmony/crypto/bls"
|
|
|
|
"github.com/harmony-one/harmony/multibls"
|
|
|
|
"github.com/harmony-one/harmony/webhooks"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
protobuf "github.com/golang/protobuf/proto"
|
|
|
|
bls_core "github.com/harmony-one/bls/ffi/go/bls"
|
|
|
|
msg_pb "github.com/harmony-one/harmony/api/proto/message"
|
|
|
|
consensus_engine "github.com/harmony-one/harmony/consensus/engine"
|
|
|
|
"github.com/harmony-one/harmony/consensus/quorum"
|
|
|
|
"github.com/harmony-one/harmony/consensus/signature"
|
|
|
|
bls_cosi "github.com/harmony-one/harmony/crypto/bls"
|
|
|
|
"github.com/harmony-one/harmony/crypto/hash"
|
|
|
|
"github.com/harmony-one/harmony/internal/chain"
|
|
|
|
"github.com/harmony-one/harmony/internal/utils"
|
|
|
|
"github.com/harmony-one/harmony/shard"
|
|
|
|
"github.com/harmony-one/harmony/shard/committee"
|
[slash][consensus] Notice double sign & broadcast, factor out tech debt of consensus (#2152)
* [slash] Remove dead interface, associated piping
* [slash] Expand out structs
* [consensus] Write to a chan when find a case of double-signing, remove dead code
* [slash] Broadcast the noticing of a double signing
* [rawdb] CRUD for slashing candidates
* [slashing][node][proto] Broadcast the slash record after receive from consensus, handle received proto message, persist in off-chain db while pending
* [slash][node][propose-block] Add verified slashes proposed into the header in block proposal
* [slash][shard] Factor out external validator as method on shard state, add double-signature field
* [slash][engine] Apply slash, name boolean expression for sorts, use stable sort
* [slash] Abstract Ballot results so keep track of both pre and post double sign event
* [slash] Fix type errors on test code
* [slash] Read from correct rawdb
* [slash] Add epoch based guards in CRUD of slashing
* [slash] Write to correct cache for slashing candidates
* [shard] Use explicit named type of BLS Signature, use convention
* [slash] Fix mistake done in refactor, improper header used. Factor out fromSlice to set
* [slash][node] Restore newblock to master, try again minimial change
* [cx-receipts] Break up one-liner, use SliceStable, not Slice
* [network] Finish refactor that makes network message headers once
* [network] Simplify creation further of headers write
* [slash] Adjust data structure of slash after offline discussion with RJ, Chao
* [slash] Still did need signature of the double signature
* [consensus] Prepare message does not have block header
* [consensus] Soft reset three files to 968517d~1
* [consensus] Begin factor consensus network intended message out with prepare first
* [consensus] Factor out Prepared message
* [consensus] Factor out announce message creation
* [consensus] Committed Message, branch on verify sender key for clearer log
* [consensus] Committed Message Factor out
* [consensus] Do jenkins MVP of signatures adjustment
* [main][slash] Provide YAML config as webhook config for double sign event
* [consensus] Adjust signatures, whitespace, lessen GC pressure
* [consensus] Remove dead code
* [consensus] Factor out commit overloaded message, give commit payload override in construct
* [consensus] Fix travis tests
* [consensus] Provide block bytes in SubmitVote(quorum.Commit)
* [consensus] Factor out noisy sanity checks in BFT, move existing commit check earlier as was before
* [quorum] Adjust signatures in quorum
* [staking] Adjust after merge from master
* [consensus] Finish refactor of consensus
* [node] Fix import
* [consensus] Fix travis
* [consensus] Use origin/master copy of block, fix mistake of pointer to empty byte
* [consensus] Less verbose bools
* [consensus] Remove unused trailing mutation hook in message construct
* [consensus] Address some TODOs on err, comment out double sign
5 years ago
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/rs/zerolog"
|
|
|
|
)
|
|
|
|
|
|
|
|
// WaitForNewRandomness listens to the RndChannel to receive new VDF randomness.
|
|
|
|
func (consensus *Consensus) WaitForNewRandomness() {
|
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
vdfOutput := <-consensus.RndChannel
|
|
|
|
consensus.pendingRnds = append(consensus.pendingRnds, vdfOutput)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetNextRnd returns the oldest available randomness along with the hash of the block there randomness preimage is committed.
|
|
|
|
func (consensus *Consensus) GetNextRnd() ([vdFAndProofSize]byte, [32]byte, error) {
|
|
|
|
if len(consensus.pendingRnds) == 0 {
|
|
|
|
return [vdFAndProofSize]byte{}, [32]byte{}, errors.New("No available randomness")
|
|
|
|
}
|
|
|
|
vdfOutput := consensus.pendingRnds[0]
|
|
|
|
|
|
|
|
vdfBytes := [vdFAndProofSize]byte{}
|
|
|
|
seed := [32]byte{}
|
|
|
|
copy(vdfBytes[:], vdfOutput[:vdFAndProofSize])
|
|
|
|
copy(seed[:], vdfOutput[vdFAndProofSize:])
|
|
|
|
|
|
|
|
//pop the first vdfOutput from the list
|
|
|
|
consensus.pendingRnds = consensus.pendingRnds[1:]
|
|
|
|
|
|
|
|
return vdfBytes, seed, nil
|
|
|
|
}
|
|
|
|
|
[double-sign] Provide proof of double sign in slash record sent to beaconchain (#2253)
* [double-sign] Commit changes in consensus needed for double-sign
* [double-sign] Leader captures when valdator double signs, broadcasts to beaconchain
* [slash] Add quick iteration tool for testing double-signing
* [slash] Add webhook example
* [slash] Add http server for hook to trigger double sign behavior
* [double-sign] Use bin/trigger-double-sign to cause a double-sign
* [double-sign] Full feedback loop working
* [slash] Thread through the slash records in the block proposal step
* [slash] Compute the slashing rate
* [double-sign] Generalize yaml malicious for many keys
* [double-sign][slash] Modify data structures, verify via webhook handler
* [slash][double-sign] Find one address of bls public key signer, seemingly settle on data structures
* [slash] Apply to state slashing for double signing
* [slash][double-sign] Checkpoint for working code that slashes on beaconchain
* [slash] Keep track of the total slash and total reporters reward
* [slash] Dump account state before and after the slash
* [slash] Satisfy Travis
* [slash][state] Apply slash to the snapshot at beginning of epoch, now need to capture also the new delegates
* [slash] Capture the unique new delegations since snapshot as well
* [slash] Filter undelegation by epoch of double sign
* [slash] Add TODO of correctness needed in slash needs on off-chain data
* [rpc] Fix closure issue on shardID
* [slash] Add delegator to double-sign testing script
* [slash] Expand crt-validator.sh with commenting printfs and make delegation
* [slash] Finish track payment of leftover slash debt after undelegation runs out
* [slash] Now be explicit about error wrt delegatorSlashApply
* [slash] Capture specific sanity check on slash paidoff
* [slash] Track slash from undelegation piecemeal
* [slash][delegation] Named slice types, .String()
* [slash] Do no RLP encode twice, once is enough
* [slash] Remove special case of validators own delegation
* [slash] Refactor approach to slash state application
* [slash] Begin expanding out Verify
* [slash] Slash on snapshot delegations, not current
* [slash] Fix Epoch Cmp
* [slash] Third iteration on slash logic
* [slash] Use full slash amount
* [slash] More log, whitespace
* [slash] Remove Println, add log
* [slash] Remove debug Println
* [slash] Add record in unit test
* [slash] Build Validator snapshot, current. Fill out slash record
* [slash] Need to get RLP dump of a header to use in test
* [slash] Factor out double sign test constants
* [slash] Factor out common for validator, stub out slash application, finish out deserialization setup
* [slash] Factor out data structure creation because of var lexical scoping
* [slash] Seem to have pipeline of unit test e2e executing
* [slash] Add expected snitch, slash amounts
* [slash] Checkpoint
* [slash] Unit test correctly checks case of validator own stake which could drop below 1 ONE in slashing
* [config] add double-sign testnet config (#1)
Signed-off-by: Leo Chen <leo@harmony.one>
* [slash] Commit for as is code & data of current dump.json
* [slash] Order of state operation not correct in test, hence bad results, thank you dlv
* [slash] Add snapshot state dump
* [slash] Pay off slash of validator own delegation correctly
* [slash] Pay off slash debt with special case for min-self
* [slash] Pass first scenario conclusively
* [slash] 2% slash passes unit test for own delegation and external
* [slash] Parameterize unit test to easily test .02 vs .80 slash
* [slash] Handle own delegation correctly at 80% slash
* [slash] Have 80% slash working with external delegator
* [slash] Remove debug code from slash
* [slash] Adjust Apply signature, test again for 2% slash
* [slash] Factor out scenario in testing so can test 2% and 80% at same time
* [slash] Correct balance deduction on plan delegation
* [slash] Mock out ChainReader for TestVerify
* [slash] Small surface area interface, now feedback loop for verify
* [slash] Remove development json
* [slash] trigger-double-sign consumes yaml
* [slash] Remove dead code
* [slash][test] Factor ValidatorWrapper into scenario
* [slash][test] Add example from local-testing dump - caution might be off
* [slash] Factor out mutation of slashDebt
* [slash][test] Factor out tests so can easily load test-case from bytes
* [slash] Fix payment mistake in validator own delegation wrt min-self-delgation respected
* [slash] Satisfy Travis
* [slash] Begin cleanup of PR
* [slash] Apply slash from header to Finalize via state processor
* [slash] Productionize code, Println => logs; adjust slash picked in newblock
* [slash] Need pointer for rlp.Decode
* [slash] ValidatorInformation use full wrapper
* Fix median stake
* [staking] Adjust MarshalJSON for Validator, Wrapper
* Refactor offchain data commit; Make block onchain/offchain commit atomic (#2279)
* Refactor offchain data; Add epoch to ValidatorSnapshot
* Make block onchain/offchain data commit atomically
* [slash][committee] Set .Active to false on double sign, do not consider banned or inactive for committee assignment
* [effective] VC eligible.go
* [consensus] Redundant field in printf
* [docker] import-ks for a dev account
* [slash] Create BLS key for dockerfile and crt-validator.sh
* [slash][docker] Easy deployment of double-sign testing
* [docker] Have slash work as single docker command
* [rpc] Fix median-stake RPC
* [slash] Update webhook with default docker BLS key
* [docker][slash] Fresh yaml copy for docker build, remove dev code in main.go
* [slash] Remove helper binary, commented out code, change to local config
* [params] Factor out test genesis value
* Add shard checking to Tx-Pool & correct blacklist (#2301)
* [core] Fix blacklist & add shardID check
* [staking + node + cmd] Fix blacklist & add shardID check
* [slash] Adjust to PR comments part 1
* [docker] Use different throw away funded account
* [docker] Create easier testing for delegation with private keys
* [docker] Update yaml
* [slash] Remove special case for slashing validator own delegation wrt min-self-delegate
* [docker] Install nano as well
* [slash] Early error if banned
* [quorum] Expose earning account in decider marshal json
* Revert "Refactor offchain data commit; Make block onchain/offchain commit atomic (#2279)"
This reverts commit 9ffbf682c075b49188923c65a0bbf39ac188be00.
* [slash] Add non-sanity check way to update validator
* [reward] Increase percision on percentage in schedule
* [slash] Adjust logs
* [committee] Check eligibility of validator before doing sanity check
* [slash] Update docker
* [slash] Move create validator script to test
* [slash] More log
* [param] Make things faster
* [slash][off-chain] Clear out slashes from pending in writeblockwithstate
* [cross-link] Log is not error, just info
* [blockchain] Not necessary to guard DeletePendingSlashingCandidates
* [slash][consensus] Use plain []byte for signature b/c bls.Sign has private impl fields, rlp does not encode that
* [slash][test] Use faucet as sender, assume user imported
* [slash] Test setup
* [slash] reserve error for real error in logs
* [slash][availability] Apply availability correct, bump signing count each block
* [slash][staking] Consider banned field in sanity check, pay snitch only half of what was actually slashed
* [slash] Pay as much as can
* [slash] use right nowAmt
* [slash] Take away from rewards as well
* [slash] iterate faster
* [slash] Remove dev based timing
* [slash] Add more log, sanity check incoming slash records, only count external for slash rate
* [availability][state] Adjust signature of ValidatorWrapper wrt state, filter out for staked validators, correct availaibility measure on running counters
* [availability] More log
* [slash] Simply pre slash erra slashing
* [slash] Remove development code
* [slash] Use height from recvMsg, todo on epoch
* [staking] Not necessary to touch LastEpochInCommittee in staking_verifier
* [slash] Undo ds in endpoint pattern config
* [slash] Add TODO and log when delegation becomes 0 b/c slash debt payment
* [slash] Abstract staked validators from shard.State into type, set slash rate based BLSKey count
Co-authored-by: Leo Chen <leo@harmony.one>
Co-authored-by: flicker-harmony <52401354+flicker-harmony@users.noreply.github.com>
Co-authored-by: Rongjian Lan <rongjian@harmony.one>
Co-authored-by: Daniel Van Der Maden <daniel@harmony.one>
5 years ago
|
|
|
var (
|
|
|
|
empty = []byte{}
|
|
|
|
)
|
|
|
|
|
|
|
|
// Signs the consensus message and returns the marshaled message.
|
|
|
|
func (consensus *Consensus) signAndMarshalConsensusMessage(message *msg_pb.Message,
|
|
|
|
priKey *bls_core.SecretKey) ([]byte, error) {
|
|
|
|
if err := consensus.signConsensusMessage(message, priKey); err != nil {
|
[double-sign] Provide proof of double sign in slash record sent to beaconchain (#2253)
* [double-sign] Commit changes in consensus needed for double-sign
* [double-sign] Leader captures when valdator double signs, broadcasts to beaconchain
* [slash] Add quick iteration tool for testing double-signing
* [slash] Add webhook example
* [slash] Add http server for hook to trigger double sign behavior
* [double-sign] Use bin/trigger-double-sign to cause a double-sign
* [double-sign] Full feedback loop working
* [slash] Thread through the slash records in the block proposal step
* [slash] Compute the slashing rate
* [double-sign] Generalize yaml malicious for many keys
* [double-sign][slash] Modify data structures, verify via webhook handler
* [slash][double-sign] Find one address of bls public key signer, seemingly settle on data structures
* [slash] Apply to state slashing for double signing
* [slash][double-sign] Checkpoint for working code that slashes on beaconchain
* [slash] Keep track of the total slash and total reporters reward
* [slash] Dump account state before and after the slash
* [slash] Satisfy Travis
* [slash][state] Apply slash to the snapshot at beginning of epoch, now need to capture also the new delegates
* [slash] Capture the unique new delegations since snapshot as well
* [slash] Filter undelegation by epoch of double sign
* [slash] Add TODO of correctness needed in slash needs on off-chain data
* [rpc] Fix closure issue on shardID
* [slash] Add delegator to double-sign testing script
* [slash] Expand crt-validator.sh with commenting printfs and make delegation
* [slash] Finish track payment of leftover slash debt after undelegation runs out
* [slash] Now be explicit about error wrt delegatorSlashApply
* [slash] Capture specific sanity check on slash paidoff
* [slash] Track slash from undelegation piecemeal
* [slash][delegation] Named slice types, .String()
* [slash] Do no RLP encode twice, once is enough
* [slash] Remove special case of validators own delegation
* [slash] Refactor approach to slash state application
* [slash] Begin expanding out Verify
* [slash] Slash on snapshot delegations, not current
* [slash] Fix Epoch Cmp
* [slash] Third iteration on slash logic
* [slash] Use full slash amount
* [slash] More log, whitespace
* [slash] Remove Println, add log
* [slash] Remove debug Println
* [slash] Add record in unit test
* [slash] Build Validator snapshot, current. Fill out slash record
* [slash] Need to get RLP dump of a header to use in test
* [slash] Factor out double sign test constants
* [slash] Factor out common for validator, stub out slash application, finish out deserialization setup
* [slash] Factor out data structure creation because of var lexical scoping
* [slash] Seem to have pipeline of unit test e2e executing
* [slash] Add expected snitch, slash amounts
* [slash] Checkpoint
* [slash] Unit test correctly checks case of validator own stake which could drop below 1 ONE in slashing
* [config] add double-sign testnet config (#1)
Signed-off-by: Leo Chen <leo@harmony.one>
* [slash] Commit for as is code & data of current dump.json
* [slash] Order of state operation not correct in test, hence bad results, thank you dlv
* [slash] Add snapshot state dump
* [slash] Pay off slash of validator own delegation correctly
* [slash] Pay off slash debt with special case for min-self
* [slash] Pass first scenario conclusively
* [slash] 2% slash passes unit test for own delegation and external
* [slash] Parameterize unit test to easily test .02 vs .80 slash
* [slash] Handle own delegation correctly at 80% slash
* [slash] Have 80% slash working with external delegator
* [slash] Remove debug code from slash
* [slash] Adjust Apply signature, test again for 2% slash
* [slash] Factor out scenario in testing so can test 2% and 80% at same time
* [slash] Correct balance deduction on plan delegation
* [slash] Mock out ChainReader for TestVerify
* [slash] Small surface area interface, now feedback loop for verify
* [slash] Remove development json
* [slash] trigger-double-sign consumes yaml
* [slash] Remove dead code
* [slash][test] Factor ValidatorWrapper into scenario
* [slash][test] Add example from local-testing dump - caution might be off
* [slash] Factor out mutation of slashDebt
* [slash][test] Factor out tests so can easily load test-case from bytes
* [slash] Fix payment mistake in validator own delegation wrt min-self-delgation respected
* [slash] Satisfy Travis
* [slash] Begin cleanup of PR
* [slash] Apply slash from header to Finalize via state processor
* [slash] Productionize code, Println => logs; adjust slash picked in newblock
* [slash] Need pointer for rlp.Decode
* [slash] ValidatorInformation use full wrapper
* Fix median stake
* [staking] Adjust MarshalJSON for Validator, Wrapper
* Refactor offchain data commit; Make block onchain/offchain commit atomic (#2279)
* Refactor offchain data; Add epoch to ValidatorSnapshot
* Make block onchain/offchain data commit atomically
* [slash][committee] Set .Active to false on double sign, do not consider banned or inactive for committee assignment
* [effective] VC eligible.go
* [consensus] Redundant field in printf
* [docker] import-ks for a dev account
* [slash] Create BLS key for dockerfile and crt-validator.sh
* [slash][docker] Easy deployment of double-sign testing
* [docker] Have slash work as single docker command
* [rpc] Fix median-stake RPC
* [slash] Update webhook with default docker BLS key
* [docker][slash] Fresh yaml copy for docker build, remove dev code in main.go
* [slash] Remove helper binary, commented out code, change to local config
* [params] Factor out test genesis value
* Add shard checking to Tx-Pool & correct blacklist (#2301)
* [core] Fix blacklist & add shardID check
* [staking + node + cmd] Fix blacklist & add shardID check
* [slash] Adjust to PR comments part 1
* [docker] Use different throw away funded account
* [docker] Create easier testing for delegation with private keys
* [docker] Update yaml
* [slash] Remove special case for slashing validator own delegation wrt min-self-delegate
* [docker] Install nano as well
* [slash] Early error if banned
* [quorum] Expose earning account in decider marshal json
* Revert "Refactor offchain data commit; Make block onchain/offchain commit atomic (#2279)"
This reverts commit 9ffbf682c075b49188923c65a0bbf39ac188be00.
* [slash] Add non-sanity check way to update validator
* [reward] Increase percision on percentage in schedule
* [slash] Adjust logs
* [committee] Check eligibility of validator before doing sanity check
* [slash] Update docker
* [slash] Move create validator script to test
* [slash] More log
* [param] Make things faster
* [slash][off-chain] Clear out slashes from pending in writeblockwithstate
* [cross-link] Log is not error, just info
* [blockchain] Not necessary to guard DeletePendingSlashingCandidates
* [slash][consensus] Use plain []byte for signature b/c bls.Sign has private impl fields, rlp does not encode that
* [slash][test] Use faucet as sender, assume user imported
* [slash] Test setup
* [slash] reserve error for real error in logs
* [slash][availability] Apply availability correct, bump signing count each block
* [slash][staking] Consider banned field in sanity check, pay snitch only half of what was actually slashed
* [slash] Pay as much as can
* [slash] use right nowAmt
* [slash] Take away from rewards as well
* [slash] iterate faster
* [slash] Remove dev based timing
* [slash] Add more log, sanity check incoming slash records, only count external for slash rate
* [availability][state] Adjust signature of ValidatorWrapper wrt state, filter out for staked validators, correct availaibility measure on running counters
* [availability] More log
* [slash] Simply pre slash erra slashing
* [slash] Remove development code
* [slash] Use height from recvMsg, todo on epoch
* [staking] Not necessary to touch LastEpochInCommittee in staking_verifier
* [slash] Undo ds in endpoint pattern config
* [slash] Add TODO and log when delegation becomes 0 b/c slash debt payment
* [slash] Abstract staked validators from shard.State into type, set slash rate based BLSKey count
Co-authored-by: Leo Chen <leo@harmony.one>
Co-authored-by: flicker-harmony <52401354+flicker-harmony@users.noreply.github.com>
Co-authored-by: Rongjian Lan <rongjian@harmony.one>
Co-authored-by: Daniel Van Der Maden <daniel@harmony.one>
5 years ago
|
|
|
return empty, err
|
|
|
|
}
|
|
|
|
marshaledMessage, err := protobuf.Marshal(message)
|
|
|
|
if err != nil {
|
[double-sign] Provide proof of double sign in slash record sent to beaconchain (#2253)
* [double-sign] Commit changes in consensus needed for double-sign
* [double-sign] Leader captures when valdator double signs, broadcasts to beaconchain
* [slash] Add quick iteration tool for testing double-signing
* [slash] Add webhook example
* [slash] Add http server for hook to trigger double sign behavior
* [double-sign] Use bin/trigger-double-sign to cause a double-sign
* [double-sign] Full feedback loop working
* [slash] Thread through the slash records in the block proposal step
* [slash] Compute the slashing rate
* [double-sign] Generalize yaml malicious for many keys
* [double-sign][slash] Modify data structures, verify via webhook handler
* [slash][double-sign] Find one address of bls public key signer, seemingly settle on data structures
* [slash] Apply to state slashing for double signing
* [slash][double-sign] Checkpoint for working code that slashes on beaconchain
* [slash] Keep track of the total slash and total reporters reward
* [slash] Dump account state before and after the slash
* [slash] Satisfy Travis
* [slash][state] Apply slash to the snapshot at beginning of epoch, now need to capture also the new delegates
* [slash] Capture the unique new delegations since snapshot as well
* [slash] Filter undelegation by epoch of double sign
* [slash] Add TODO of correctness needed in slash needs on off-chain data
* [rpc] Fix closure issue on shardID
* [slash] Add delegator to double-sign testing script
* [slash] Expand crt-validator.sh with commenting printfs and make delegation
* [slash] Finish track payment of leftover slash debt after undelegation runs out
* [slash] Now be explicit about error wrt delegatorSlashApply
* [slash] Capture specific sanity check on slash paidoff
* [slash] Track slash from undelegation piecemeal
* [slash][delegation] Named slice types, .String()
* [slash] Do no RLP encode twice, once is enough
* [slash] Remove special case of validators own delegation
* [slash] Refactor approach to slash state application
* [slash] Begin expanding out Verify
* [slash] Slash on snapshot delegations, not current
* [slash] Fix Epoch Cmp
* [slash] Third iteration on slash logic
* [slash] Use full slash amount
* [slash] More log, whitespace
* [slash] Remove Println, add log
* [slash] Remove debug Println
* [slash] Add record in unit test
* [slash] Build Validator snapshot, current. Fill out slash record
* [slash] Need to get RLP dump of a header to use in test
* [slash] Factor out double sign test constants
* [slash] Factor out common for validator, stub out slash application, finish out deserialization setup
* [slash] Factor out data structure creation because of var lexical scoping
* [slash] Seem to have pipeline of unit test e2e executing
* [slash] Add expected snitch, slash amounts
* [slash] Checkpoint
* [slash] Unit test correctly checks case of validator own stake which could drop below 1 ONE in slashing
* [config] add double-sign testnet config (#1)
Signed-off-by: Leo Chen <leo@harmony.one>
* [slash] Commit for as is code & data of current dump.json
* [slash] Order of state operation not correct in test, hence bad results, thank you dlv
* [slash] Add snapshot state dump
* [slash] Pay off slash of validator own delegation correctly
* [slash] Pay off slash debt with special case for min-self
* [slash] Pass first scenario conclusively
* [slash] 2% slash passes unit test for own delegation and external
* [slash] Parameterize unit test to easily test .02 vs .80 slash
* [slash] Handle own delegation correctly at 80% slash
* [slash] Have 80% slash working with external delegator
* [slash] Remove debug code from slash
* [slash] Adjust Apply signature, test again for 2% slash
* [slash] Factor out scenario in testing so can test 2% and 80% at same time
* [slash] Correct balance deduction on plan delegation
* [slash] Mock out ChainReader for TestVerify
* [slash] Small surface area interface, now feedback loop for verify
* [slash] Remove development json
* [slash] trigger-double-sign consumes yaml
* [slash] Remove dead code
* [slash][test] Factor ValidatorWrapper into scenario
* [slash][test] Add example from local-testing dump - caution might be off
* [slash] Factor out mutation of slashDebt
* [slash][test] Factor out tests so can easily load test-case from bytes
* [slash] Fix payment mistake in validator own delegation wrt min-self-delgation respected
* [slash] Satisfy Travis
* [slash] Begin cleanup of PR
* [slash] Apply slash from header to Finalize via state processor
* [slash] Productionize code, Println => logs; adjust slash picked in newblock
* [slash] Need pointer for rlp.Decode
* [slash] ValidatorInformation use full wrapper
* Fix median stake
* [staking] Adjust MarshalJSON for Validator, Wrapper
* Refactor offchain data commit; Make block onchain/offchain commit atomic (#2279)
* Refactor offchain data; Add epoch to ValidatorSnapshot
* Make block onchain/offchain data commit atomically
* [slash][committee] Set .Active to false on double sign, do not consider banned or inactive for committee assignment
* [effective] VC eligible.go
* [consensus] Redundant field in printf
* [docker] import-ks for a dev account
* [slash] Create BLS key for dockerfile and crt-validator.sh
* [slash][docker] Easy deployment of double-sign testing
* [docker] Have slash work as single docker command
* [rpc] Fix median-stake RPC
* [slash] Update webhook with default docker BLS key
* [docker][slash] Fresh yaml copy for docker build, remove dev code in main.go
* [slash] Remove helper binary, commented out code, change to local config
* [params] Factor out test genesis value
* Add shard checking to Tx-Pool & correct blacklist (#2301)
* [core] Fix blacklist & add shardID check
* [staking + node + cmd] Fix blacklist & add shardID check
* [slash] Adjust to PR comments part 1
* [docker] Use different throw away funded account
* [docker] Create easier testing for delegation with private keys
* [docker] Update yaml
* [slash] Remove special case for slashing validator own delegation wrt min-self-delegate
* [docker] Install nano as well
* [slash] Early error if banned
* [quorum] Expose earning account in decider marshal json
* Revert "Refactor offchain data commit; Make block onchain/offchain commit atomic (#2279)"
This reverts commit 9ffbf682c075b49188923c65a0bbf39ac188be00.
* [slash] Add non-sanity check way to update validator
* [reward] Increase percision on percentage in schedule
* [slash] Adjust logs
* [committee] Check eligibility of validator before doing sanity check
* [slash] Update docker
* [slash] Move create validator script to test
* [slash] More log
* [param] Make things faster
* [slash][off-chain] Clear out slashes from pending in writeblockwithstate
* [cross-link] Log is not error, just info
* [blockchain] Not necessary to guard DeletePendingSlashingCandidates
* [slash][consensus] Use plain []byte for signature b/c bls.Sign has private impl fields, rlp does not encode that
* [slash][test] Use faucet as sender, assume user imported
* [slash] Test setup
* [slash] reserve error for real error in logs
* [slash][availability] Apply availability correct, bump signing count each block
* [slash][staking] Consider banned field in sanity check, pay snitch only half of what was actually slashed
* [slash] Pay as much as can
* [slash] use right nowAmt
* [slash] Take away from rewards as well
* [slash] iterate faster
* [slash] Remove dev based timing
* [slash] Add more log, sanity check incoming slash records, only count external for slash rate
* [availability][state] Adjust signature of ValidatorWrapper wrt state, filter out for staked validators, correct availaibility measure on running counters
* [availability] More log
* [slash] Simply pre slash erra slashing
* [slash] Remove development code
* [slash] Use height from recvMsg, todo on epoch
* [staking] Not necessary to touch LastEpochInCommittee in staking_verifier
* [slash] Undo ds in endpoint pattern config
* [slash] Add TODO and log when delegation becomes 0 b/c slash debt payment
* [slash] Abstract staked validators from shard.State into type, set slash rate based BLSKey count
Co-authored-by: Leo Chen <leo@harmony.one>
Co-authored-by: flicker-harmony <52401354+flicker-harmony@users.noreply.github.com>
Co-authored-by: Rongjian Lan <rongjian@harmony.one>
Co-authored-by: Daniel Van Der Maden <daniel@harmony.one>
5 years ago
|
|
|
return empty, err
|
|
|
|
}
|
|
|
|
return marshaledMessage, nil
|
|
|
|
}
|
|
|
|
|
[double-sign] Provide proof of double sign in slash record sent to beaconchain (#2253)
* [double-sign] Commit changes in consensus needed for double-sign
* [double-sign] Leader captures when valdator double signs, broadcasts to beaconchain
* [slash] Add quick iteration tool for testing double-signing
* [slash] Add webhook example
* [slash] Add http server for hook to trigger double sign behavior
* [double-sign] Use bin/trigger-double-sign to cause a double-sign
* [double-sign] Full feedback loop working
* [slash] Thread through the slash records in the block proposal step
* [slash] Compute the slashing rate
* [double-sign] Generalize yaml malicious for many keys
* [double-sign][slash] Modify data structures, verify via webhook handler
* [slash][double-sign] Find one address of bls public key signer, seemingly settle on data structures
* [slash] Apply to state slashing for double signing
* [slash][double-sign] Checkpoint for working code that slashes on beaconchain
* [slash] Keep track of the total slash and total reporters reward
* [slash] Dump account state before and after the slash
* [slash] Satisfy Travis
* [slash][state] Apply slash to the snapshot at beginning of epoch, now need to capture also the new delegates
* [slash] Capture the unique new delegations since snapshot as well
* [slash] Filter undelegation by epoch of double sign
* [slash] Add TODO of correctness needed in slash needs on off-chain data
* [rpc] Fix closure issue on shardID
* [slash] Add delegator to double-sign testing script
* [slash] Expand crt-validator.sh with commenting printfs and make delegation
* [slash] Finish track payment of leftover slash debt after undelegation runs out
* [slash] Now be explicit about error wrt delegatorSlashApply
* [slash] Capture specific sanity check on slash paidoff
* [slash] Track slash from undelegation piecemeal
* [slash][delegation] Named slice types, .String()
* [slash] Do no RLP encode twice, once is enough
* [slash] Remove special case of validators own delegation
* [slash] Refactor approach to slash state application
* [slash] Begin expanding out Verify
* [slash] Slash on snapshot delegations, not current
* [slash] Fix Epoch Cmp
* [slash] Third iteration on slash logic
* [slash] Use full slash amount
* [slash] More log, whitespace
* [slash] Remove Println, add log
* [slash] Remove debug Println
* [slash] Add record in unit test
* [slash] Build Validator snapshot, current. Fill out slash record
* [slash] Need to get RLP dump of a header to use in test
* [slash] Factor out double sign test constants
* [slash] Factor out common for validator, stub out slash application, finish out deserialization setup
* [slash] Factor out data structure creation because of var lexical scoping
* [slash] Seem to have pipeline of unit test e2e executing
* [slash] Add expected snitch, slash amounts
* [slash] Checkpoint
* [slash] Unit test correctly checks case of validator own stake which could drop below 1 ONE in slashing
* [config] add double-sign testnet config (#1)
Signed-off-by: Leo Chen <leo@harmony.one>
* [slash] Commit for as is code & data of current dump.json
* [slash] Order of state operation not correct in test, hence bad results, thank you dlv
* [slash] Add snapshot state dump
* [slash] Pay off slash of validator own delegation correctly
* [slash] Pay off slash debt with special case for min-self
* [slash] Pass first scenario conclusively
* [slash] 2% slash passes unit test for own delegation and external
* [slash] Parameterize unit test to easily test .02 vs .80 slash
* [slash] Handle own delegation correctly at 80% slash
* [slash] Have 80% slash working with external delegator
* [slash] Remove debug code from slash
* [slash] Adjust Apply signature, test again for 2% slash
* [slash] Factor out scenario in testing so can test 2% and 80% at same time
* [slash] Correct balance deduction on plan delegation
* [slash] Mock out ChainReader for TestVerify
* [slash] Small surface area interface, now feedback loop for verify
* [slash] Remove development json
* [slash] trigger-double-sign consumes yaml
* [slash] Remove dead code
* [slash][test] Factor ValidatorWrapper into scenario
* [slash][test] Add example from local-testing dump - caution might be off
* [slash] Factor out mutation of slashDebt
* [slash][test] Factor out tests so can easily load test-case from bytes
* [slash] Fix payment mistake in validator own delegation wrt min-self-delgation respected
* [slash] Satisfy Travis
* [slash] Begin cleanup of PR
* [slash] Apply slash from header to Finalize via state processor
* [slash] Productionize code, Println => logs; adjust slash picked in newblock
* [slash] Need pointer for rlp.Decode
* [slash] ValidatorInformation use full wrapper
* Fix median stake
* [staking] Adjust MarshalJSON for Validator, Wrapper
* Refactor offchain data commit; Make block onchain/offchain commit atomic (#2279)
* Refactor offchain data; Add epoch to ValidatorSnapshot
* Make block onchain/offchain data commit atomically
* [slash][committee] Set .Active to false on double sign, do not consider banned or inactive for committee assignment
* [effective] VC eligible.go
* [consensus] Redundant field in printf
* [docker] import-ks for a dev account
* [slash] Create BLS key for dockerfile and crt-validator.sh
* [slash][docker] Easy deployment of double-sign testing
* [docker] Have slash work as single docker command
* [rpc] Fix median-stake RPC
* [slash] Update webhook with default docker BLS key
* [docker][slash] Fresh yaml copy for docker build, remove dev code in main.go
* [slash] Remove helper binary, commented out code, change to local config
* [params] Factor out test genesis value
* Add shard checking to Tx-Pool & correct blacklist (#2301)
* [core] Fix blacklist & add shardID check
* [staking + node + cmd] Fix blacklist & add shardID check
* [slash] Adjust to PR comments part 1
* [docker] Use different throw away funded account
* [docker] Create easier testing for delegation with private keys
* [docker] Update yaml
* [slash] Remove special case for slashing validator own delegation wrt min-self-delegate
* [docker] Install nano as well
* [slash] Early error if banned
* [quorum] Expose earning account in decider marshal json
* Revert "Refactor offchain data commit; Make block onchain/offchain commit atomic (#2279)"
This reverts commit 9ffbf682c075b49188923c65a0bbf39ac188be00.
* [slash] Add non-sanity check way to update validator
* [reward] Increase percision on percentage in schedule
* [slash] Adjust logs
* [committee] Check eligibility of validator before doing sanity check
* [slash] Update docker
* [slash] Move create validator script to test
* [slash] More log
* [param] Make things faster
* [slash][off-chain] Clear out slashes from pending in writeblockwithstate
* [cross-link] Log is not error, just info
* [blockchain] Not necessary to guard DeletePendingSlashingCandidates
* [slash][consensus] Use plain []byte for signature b/c bls.Sign has private impl fields, rlp does not encode that
* [slash][test] Use faucet as sender, assume user imported
* [slash] Test setup
* [slash] reserve error for real error in logs
* [slash][availability] Apply availability correct, bump signing count each block
* [slash][staking] Consider banned field in sanity check, pay snitch only half of what was actually slashed
* [slash] Pay as much as can
* [slash] use right nowAmt
* [slash] Take away from rewards as well
* [slash] iterate faster
* [slash] Remove dev based timing
* [slash] Add more log, sanity check incoming slash records, only count external for slash rate
* [availability][state] Adjust signature of ValidatorWrapper wrt state, filter out for staked validators, correct availaibility measure on running counters
* [availability] More log
* [slash] Simply pre slash erra slashing
* [slash] Remove development code
* [slash] Use height from recvMsg, todo on epoch
* [staking] Not necessary to touch LastEpochInCommittee in staking_verifier
* [slash] Undo ds in endpoint pattern config
* [slash] Add TODO and log when delegation becomes 0 b/c slash debt payment
* [slash] Abstract staked validators from shard.State into type, set slash rate based BLSKey count
Co-authored-by: Leo Chen <leo@harmony.one>
Co-authored-by: flicker-harmony <52401354+flicker-harmony@users.noreply.github.com>
Co-authored-by: Rongjian Lan <rongjian@harmony.one>
Co-authored-by: Daniel Van Der Maden <daniel@harmony.one>
5 years ago
|
|
|
// UpdatePublicKeys updates the PublicKeys for
|
|
|
|
// quorum on current subcommittee, protected by a mutex
|
|
|
|
func (consensus *Consensus) UpdatePublicKeys(pubKeys, allowlist []bls_cosi.PublicKeyWrapper) int64 {
|
|
|
|
consensus.mutex.Lock()
|
|
|
|
defer consensus.mutex.Unlock()
|
|
|
|
return consensus.updatePublicKeys(pubKeys, allowlist)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (consensus *Consensus) updatePublicKeys(pubKeys, allowlist []bls_cosi.PublicKeyWrapper) int64 {
|
|
|
|
consensus.Decider.UpdateParticipants(pubKeys, allowlist)
|
|
|
|
consensus.getLogger().Info().Msg("My Committee updated")
|
|
|
|
for i := range pubKeys {
|
|
|
|
consensus.getLogger().Info().
|
|
|
|
Int("index", i).
|
|
|
|
Str("BLSPubKey", pubKeys[i].Bytes.Hex()).
|
|
|
|
Msg("Member")
|
|
|
|
}
|
|
|
|
|
|
|
|
allKeys := consensus.Decider.Participants()
|
|
|
|
if len(allKeys) != 0 {
|
|
|
|
consensus.LeaderPubKey = &allKeys[0]
|
|
|
|
consensus.getLogger().Info().
|
|
|
|
Str("info", consensus.LeaderPubKey.Bytes.Hex()).Msg("My Leader")
|
|
|
|
} else {
|
|
|
|
consensus.getLogger().Error().
|
|
|
|
Msg("[UpdatePublicKeys] Participants is empty")
|
|
|
|
}
|
|
|
|
for i := range pubKeys {
|
|
|
|
consensus.getLogger().Info().
|
|
|
|
Int("index", i).
|
|
|
|
Str("BLSPubKey", pubKeys[i].Bytes.Hex()).
|
|
|
|
Msg("Member")
|
|
|
|
}
|
|
|
|
// reset states after update public keys
|
|
|
|
// TODO: incorporate bitmaps in the decider, so their state can't be inconsistent.
|
|
|
|
consensus.updateBitmaps()
|
|
|
|
consensus.resetState()
|
|
|
|
|
|
|
|
// do not reset view change state if it is in view changing mode
|
|
|
|
if !consensus.isViewChangingMode() {
|
|
|
|
consensus.resetViewChangeState()
|
|
|
|
}
|
|
|
|
return consensus.Decider.ParticipantsCount()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sign on the hash of the message
|
|
|
|
func (consensus *Consensus) signMessage(message []byte, priKey *bls_core.SecretKey) []byte {
|
|
|
|
hash := hash.Keccak256(message)
|
|
|
|
signature := priKey.SignHash(hash[:])
|
|
|
|
return signature.Serialize()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sign on the consensus message signature field.
|
|
|
|
func (consensus *Consensus) signConsensusMessage(message *msg_pb.Message,
|
|
|
|
priKey *bls_core.SecretKey) error {
|
|
|
|
message.Signature = nil
|
|
|
|
marshaledMessage, err := protobuf.Marshal(message)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// 64 byte of signature on previous data
|
|
|
|
signature := consensus.signMessage(marshaledMessage, priKey)
|
|
|
|
message.Signature = signature
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateBitmaps update the bitmaps for prepare and commit phase
|
|
|
|
func (consensus *Consensus) updateBitmaps() {
|
|
|
|
consensus.getLogger().Debug().
|
|
|
|
Str("MessageType", consensus.phase.String()).
|
|
|
|
Msg("[UpdateBitmaps] Updating consensus bitmaps")
|
|
|
|
members := consensus.Decider.Participants()
|
|
|
|
prepareBitmap := bls_cosi.NewMask(members)
|
|
|
|
commitBitmap := bls_cosi.NewMask(members)
|
|
|
|
multiSigBitmap := bls_cosi.NewMask(members)
|
|
|
|
consensus.prepareBitmap = prepareBitmap
|
|
|
|
consensus.commitBitmap = commitBitmap
|
|
|
|
consensus.multiSigBitmap = multiSigBitmap
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// ResetState resets the state of the consensus
|
|
|
|
func (consensus *Consensus) resetState() {
|
|
|
|
consensus.switchPhase("ResetState", FBFTAnnounce)
|
|
|
|
|
|
|
|
consensus.blockHash = [32]byte{}
|
|
|
|
consensus.block = []byte{}
|
|
|
|
consensus.Decider.ResetPrepareAndCommitVotes()
|
|
|
|
if consensus.prepareBitmap != nil {
|
|
|
|
consensus.prepareBitmap.Clear()
|
|
|
|
}
|
|
|
|
if consensus.commitBitmap != nil {
|
|
|
|
consensus.commitBitmap.Clear()
|
|
|
|
}
|
|
|
|
consensus.aggregatedPrepareSig = nil
|
|
|
|
consensus.aggregatedCommitSig = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsValidatorInCommittee returns whether the given validator BLS address is part of my committee
|
|
|
|
func (consensus *Consensus) IsValidatorInCommittee(pubKey bls.SerializedPublicKey) bool {
|
|
|
|
consensus.mutex.RLock()
|
|
|
|
defer consensus.mutex.RUnlock()
|
|
|
|
return consensus.isValidatorInCommittee(pubKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (consensus *Consensus) isValidatorInCommittee(pubKey bls.SerializedPublicKey) bool {
|
|
|
|
return consensus.Decider.IndexOf(pubKey) != -1
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetMode sets the mode of consensus
|
|
|
|
func (consensus *Consensus) SetMode(m Mode) {
|
|
|
|
consensus.mutex.Lock()
|
|
|
|
defer consensus.mutex.Unlock()
|
|
|
|
consensus.setMode(m)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetMode sets the mode of consensus
|
|
|
|
func (consensus *Consensus) setMode(m Mode) {
|
|
|
|
if m == Normal && consensus.isBackup {
|
|
|
|
m = NormalBackup
|
|
|
|
}
|
|
|
|
|
|
|
|
consensus.getLogger().Debug().
|
|
|
|
Str("Mode", m.String()).
|
|
|
|
Msg("[SetMode]")
|
|
|
|
consensus.current.SetMode(m)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetIsBackup sets the mode of consensus
|
|
|
|
func (consensus *Consensus) SetIsBackup(isBackup bool) {
|
|
|
|
consensus.getLogger().Debug().
|
|
|
|
Bool("IsBackup", isBackup).
|
|
|
|
Msg("[SetIsBackup]")
|
|
|
|
consensus.isBackup = isBackup
|
|
|
|
consensus.current.SetIsBackup(isBackup)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mode returns the mode of consensus
|
|
|
|
func (consensus *Consensus) Mode() Mode {
|
|
|
|
consensus.mutex.RLock()
|
|
|
|
defer consensus.mutex.RUnlock()
|
|
|
|
return consensus.mode()
|
|
|
|
}
|
|
|
|
|
|
|
|
// mode returns the mode of consensus
|
|
|
|
func (consensus *Consensus) mode() Mode {
|
|
|
|
return consensus.current.Mode()
|
|
|
|
}
|
|
|
|
|
|
|
|
// RegisterPRndChannel registers the channel for receiving randomness preimage from DRG protocol
|
|
|
|
func (consensus *Consensus) RegisterPRndChannel(pRndChannel chan []byte) {
|
|
|
|
consensus.PRndChannel = pRndChannel
|
|
|
|
}
|
|
|
|
|
|
|
|
// RegisterRndChannel registers the channel for receiving final randomness from DRG protocol
|
|
|
|
func (consensus *Consensus) RegisterRndChannel(rndChannel chan [548]byte) {
|
|
|
|
consensus.RndChannel = rndChannel
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check viewID, caller's responsibility to hold lock when change ignoreViewIDCheck
|
|
|
|
func (consensus *Consensus) checkViewID(msg *FBFTMessage) error {
|
|
|
|
// just ignore consensus check for the first time when node join
|
|
|
|
if consensus.IgnoreViewIDCheck.IsSet() {
|
|
|
|
//in syncing mode, node accepts incoming messages without viewID/leaderKey checking
|
|
|
|
//so only set mode to normal when new node enters consensus and need checking viewID
|
|
|
|
consensus.setMode(Normal)
|
|
|
|
consensus.setViewIDs(msg.ViewID)
|
|
|
|
if !msg.HasSingleSender() {
|
|
|
|
return errors.New("Leader message can not have multiple sender keys")
|
|
|
|
}
|
|
|
|
consensus.LeaderPubKey = msg.SenderPubkeys[0]
|
|
|
|
consensus.IgnoreViewIDCheck.UnSet()
|
|
|
|
consensus.consensusTimeout[timeoutConsensus].Start()
|
|
|
|
consensus.getLogger().Info().
|
|
|
|
Str("leaderKey", consensus.LeaderPubKey.Bytes.Hex()).
|
|
|
|
Msg("[checkViewID] Start consensus timer")
|
|
|
|
return nil
|
|
|
|
} else if msg.ViewID > consensus.getCurBlockViewID() {
|
|
|
|
return consensus_engine.ErrViewIDNotMatch
|
|
|
|
} else if msg.ViewID < consensus.getCurBlockViewID() {
|
|
|
|
return errors.New("view ID belongs to the past")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetBlockNum sets the blockNum in consensus object, called at node bootstrap
|
|
|
|
func (consensus *Consensus) SetBlockNum(blockNum uint64) {
|
|
|
|
atomic.StoreUint64(&consensus.blockNum, blockNum)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetBlockNum sets the blockNum in consensus object, called at node bootstrap
|
|
|
|
func (consensus *Consensus) setBlockNum(blockNum uint64) {
|
|
|
|
atomic.StoreUint64(&consensus.blockNum, blockNum)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReadSignatureBitmapPayload read the payload for signature and bitmap; offset is the beginning position of reading
|
|
|
|
func (consensus *Consensus) ReadSignatureBitmapPayload(recvPayload []byte, offset int) (*bls_core.Sign, *bls_cosi.Mask, error) {
|
|
|
|
consensus.mutex.RLock()
|
|
|
|
members := consensus.Decider.Participants()
|
|
|
|
consensus.mutex.RUnlock()
|
|
|
|
return consensus.readSignatureBitmapPayload(recvPayload, offset, members)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (consensus *Consensus) readSignatureBitmapPayload(recvPayload []byte, offset int, members multibls.PublicKeys) (*bls_core.Sign, *bls_cosi.Mask, error) {
|
|
|
|
if offset+bls.BLSSignatureSizeInBytes > len(recvPayload) {
|
|
|
|
return nil, nil, errors.New("payload not have enough length")
|
|
|
|
}
|
|
|
|
sigAndBitmapPayload := recvPayload[offset:]
|
|
|
|
|
|
|
|
// TODO(audit): keep a Mask in the Decider so it won't be reconstructed on the fly.
|
|
|
|
return chain.ReadSignatureBitmapByPublicKeys(
|
|
|
|
sigAndBitmapPayload, members,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateConsensusInformation will update shard information (epoch, publicKeys, blockNum, viewID)
|
|
|
|
// based on the local blockchain. It is called in two cases for now:
|
|
|
|
// 1. consensus object initialization. because of current dependency where chainreader is only available
|
|
|
|
// after node is initialized; node is only available after consensus is initialized
|
|
|
|
// we need call this function separately after create consensus object
|
|
|
|
// 2. after state syncing is finished
|
|
|
|
// It will return the mode:
|
|
|
|
// (a) node not in committed: Listening mode
|
|
|
|
// (b) node in committed but has any err during processing: Syncing mode
|
|
|
|
// (c) node in committed and everything looks good: Normal mode
|
|
|
|
func (consensus *Consensus) UpdateConsensusInformation() Mode {
|
|
|
|
consensus.mutex.Lock()
|
|
|
|
defer consensus.mutex.Unlock()
|
|
|
|
return consensus.updateConsensusInformation()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (consensus *Consensus) updateConsensusInformation() Mode {
|
|
|
|
curHeader := consensus.Blockchain().CurrentHeader()
|
|
|
|
curEpoch := curHeader.Epoch()
|
|
|
|
nextEpoch := new(big.Int).Add(curHeader.Epoch(), common.Big1)
|
|
|
|
|
|
|
|
// Overwrite nextEpoch if the shard state has a epoch number
|
|
|
|
if curHeader.IsLastBlockInEpoch() {
|
|
|
|
nextShardState, err := curHeader.GetShardState()
|
|
|
|
if err != nil {
|
|
|
|
consensus.getLogger().Error().
|
|
|
|
Err(err).
|
|
|
|
Uint32("shard", consensus.ShardID).
|
|
|
|
Msg("[UpdateConsensusInformation] Error retrieving current shard state in the first block")
|
|
|
|
return Syncing
|
|
|
|
}
|
|
|
|
if nextShardState.Epoch != nil {
|
|
|
|
nextEpoch = nextShardState.Epoch
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
consensus.BlockPeriod = 5 * time.Second
|
|
|
|
|
|
|
|
// Enable 2s block time at the twoSecondsEpoch
|
|
|
|
if consensus.Blockchain().Config().IsTwoSeconds(nextEpoch) {
|
|
|
|
consensus.BlockPeriod = 2 * time.Second
|
|
|
|
}
|
|
|
|
|
|
|
|
isFirstTimeStaking := consensus.Blockchain().Config().IsStaking(nextEpoch) &&
|
|
|
|
curHeader.IsLastBlockInEpoch() && !consensus.Blockchain().Config().IsStaking(curEpoch)
|
|
|
|
haventUpdatedDecider := consensus.Blockchain().Config().IsStaking(curEpoch) &&
|
|
|
|
consensus.Decider.Policy() != quorum.SuperMajorityStake
|
|
|
|
|
|
|
|
// Only happens once, the flip-over to a new Decider policy
|
|
|
|
if isFirstTimeStaking || haventUpdatedDecider {
|
[rpc][availability][apr] Richer validator information, implement APR, unify EPoS computation, remove fall 2019 tech debt (#2484)
* [rpc][validator] Extend hmy blockchain validator information
* [availability] Optimize bump count
* [staking][validator][rpc] Remove validator stats rpc, fold into validator information, make existing pattern default behavior
* [slash] Reimplement SetDifference
* [reward][engine][network] Remove bad API from fall, begin setup for Per validator awards
* [header] Custom Marshal header for downstream, remove dev code
* [effective][committee] Factor out EPoS round of computation thereby unification in codebase of EPoS
* [unit-test] Fix semantically wrong validator unit tests, punt on maxBLS key wrt tx-pool test
* [reward] Use excellent singleflight package for caching lookup of subcommittees
* [apr][reward] Begin APR package itself, iterate on iterface signatures
* [reward] Handle possible error from singleflight
* [rpc][validator][reward] Adjust RPC committees, singleflight on votingPower, foldStats into Validator Information
* [apr] Stub out computation of APR
* [effective][committee] Upgrade SlotPurchase with named fields, provide marshal
* [effective] Update Tests
* [blockchain] TODO Remove the validators no longer in committee
* [validator][effective] More expressive string representation of eligibilty, ValidatorRPC explicit say if in committee now
* [rpc] Median-stake more semantic meaningful
* [validator] Iterate on semantic meaning of JSON representation
* [offchain] Make validator stats return explicit error
* [availability] Small typo
* [rpc] Quick visual hack until fix delete out kicked out validators
* [offchain] Delete validator from offchain that lost their slot
* [apr] Forgot to update interface signature
* [apr] Mul instead of Div
* [protocol][validator] Fold block reward accum per vaidator into validator-wrapper, off-chain => on-chain
* [votepower] Refactor votepower Roster, simplify aggregation of network wide rosters
* [votepower][shard] Adjust roster, optimize usage of BLSPublicKey as key, use MarshalText trick
* [shard] Granular errors
* [votepower][validator] Unify votepower data structure with off-chain usage
* [votepower][consensus][validator] Further simplify and unify votepower with off-chain, validator stats
* [votepower] Use RJs naming convention group,overall
* [votepower] Remove Println, do keep enforcing order
* [effective][reward] Expand semantics of eligibility as it was overloaded and confusing, evict old voting power computations
* [apr] Adjust json field name
* [votepower] Only aggregate on external validator
* [votepower] Mistake on aggregation, custom presentation network-wide
* [rpc][validator][availability] Remove parameter, take into account empty snapshot
* [apr] Use snapshots from two, one epochs ago. Still have question on header
* [apr] Use GetHeaderByNumber for the header needed for time stamp
* [chain] Evict > 3 epoch old voting power
* [blockchain] Leave Delete Validator snapshot as TODO
* [validator][rpc][effective] Undo changes to Protocol field, use virtual construct at RPC layer for meaning
* [project] Address PR comments
* [committee][rpc] Move +1 to computation of epos round rather than hack mutation
* [reward] Remove entire unnecessary loop, hook on AddReward. Remove unnecessary new big int
* [votepower][rpc][validator] Stick with numeric.Dec for token involved with computation, expose accumulate block-reward in RPC
* [effective][committee] Track the candidates for the EPoS auction, RPC median-stake benefits
* [node] Add hack way to get real error reason of why cannot load shardchain
* [consensus] Expand log on current issue on nil block
* [apr] Do the actual call to compute for validator's APR
* [committee] Wrap SlotOrder with validator address, manifests in median-stake RPC
* [apr] Incorrect error handle order
* [quorum] Remove incorrect compare on bls Key, (typo), remove redundant error check
* [shard] Add log if stakedSlots is 0
* [apr] More sanity check on div by zero, more lenient on error when dont have historical data yet
* [committee] Remove + 1 on seat count
* [apr] Use int64() directly
* [apr] Log when odd empty nil header
* [apr] Do not crash on empty header, figure out later
5 years ago
|
|
|
decider := quorum.NewDecider(quorum.SuperMajorityStake, consensus.ShardID)
|
|
|
|
consensus.Decider = decider
|
|
|
|
}
|
|
|
|
|
|
|
|
var committeeToSet *shard.Committee
|
|
|
|
epochToSet := curEpoch
|
|
|
|
hasError := false
|
|
|
|
curShardState, err := committee.WithStakingEnabled.ReadFromDB(
|
|
|
|
curEpoch, consensus.Blockchain(),
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
consensus.getLogger().Error().
|
|
|
|
Err(err).
|
|
|
|
Uint32("shard", consensus.ShardID).
|
|
|
|
Msg("[UpdateConsensusInformation] Error retrieving current shard state")
|
|
|
|
return Syncing
|
|
|
|
}
|
|
|
|
|
|
|
|
consensus.getLogger().Info().Msg("[UpdateConsensusInformation] Updating.....")
|
|
|
|
// genesis block is a special case that will have shard state and needs to skip processing
|
|
|
|
isNotGenesisBlock := curHeader.Number().Cmp(big.NewInt(0)) > 0
|
|
|
|
if curHeader.IsLastBlockInEpoch() && isNotGenesisBlock {
|
|
|
|
|
|
|
|
nextShardState, err := committee.WithStakingEnabled.ReadFromDB(
|
|
|
|
nextEpoch, consensus.Blockchain(),
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
consensus.getLogger().Error().
|
|
|
|
Err(err).
|
|
|
|
Uint32("shard", consensus.ShardID).
|
|
|
|
Msg("Error retrieving nextEpoch shard state")
|
|
|
|
return Syncing
|
|
|
|
}
|
|
|
|
|
|
|
|
subComm, err := nextShardState.FindCommitteeByID(curHeader.ShardID())
|
|
|
|
if err != nil {
|
|
|
|
consensus.getLogger().Error().
|
|
|
|
Err(err).
|
|
|
|
Uint32("shard", consensus.ShardID).
|
|
|
|
Msg("Error retrieving nextEpoch shard state")
|
|
|
|
return Syncing
|
|
|
|
}
|
|
|
|
|
|
|
|
committeeToSet = subComm
|
|
|
|
epochToSet = nextEpoch
|
|
|
|
} else {
|
|
|
|
subComm, err := curShardState.FindCommitteeByID(curHeader.ShardID())
|
|
|
|
if err != nil {
|
|
|
|
consensus.getLogger().Error().
|
|
|
|
Err(err).
|
|
|
|
Uint32("shard", consensus.ShardID).
|
|
|
|
Msg("Error retrieving current shard state")
|
|
|
|
return Syncing
|
|
|
|
}
|
|
|
|
|
|
|
|
committeeToSet = subComm
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(committeeToSet.Slots) == 0 {
|
|
|
|
consensus.getLogger().Warn().
|
|
|
|
Msg("[UpdateConsensusInformation] No members in the committee to update")
|
|
|
|
hasError = true
|
|
|
|
}
|
|
|
|
|
|
|
|
// update public keys in the committee
|
|
|
|
oldLeader := consensus.LeaderPubKey
|
[rpc][availability][apr] Richer validator information, implement APR, unify EPoS computation, remove fall 2019 tech debt (#2484)
* [rpc][validator] Extend hmy blockchain validator information
* [availability] Optimize bump count
* [staking][validator][rpc] Remove validator stats rpc, fold into validator information, make existing pattern default behavior
* [slash] Reimplement SetDifference
* [reward][engine][network] Remove bad API from fall, begin setup for Per validator awards
* [header] Custom Marshal header for downstream, remove dev code
* [effective][committee] Factor out EPoS round of computation thereby unification in codebase of EPoS
* [unit-test] Fix semantically wrong validator unit tests, punt on maxBLS key wrt tx-pool test
* [reward] Use excellent singleflight package for caching lookup of subcommittees
* [apr][reward] Begin APR package itself, iterate on iterface signatures
* [reward] Handle possible error from singleflight
* [rpc][validator][reward] Adjust RPC committees, singleflight on votingPower, foldStats into Validator Information
* [apr] Stub out computation of APR
* [effective][committee] Upgrade SlotPurchase with named fields, provide marshal
* [effective] Update Tests
* [blockchain] TODO Remove the validators no longer in committee
* [validator][effective] More expressive string representation of eligibilty, ValidatorRPC explicit say if in committee now
* [rpc] Median-stake more semantic meaningful
* [validator] Iterate on semantic meaning of JSON representation
* [offchain] Make validator stats return explicit error
* [availability] Small typo
* [rpc] Quick visual hack until fix delete out kicked out validators
* [offchain] Delete validator from offchain that lost their slot
* [apr] Forgot to update interface signature
* [apr] Mul instead of Div
* [protocol][validator] Fold block reward accum per vaidator into validator-wrapper, off-chain => on-chain
* [votepower] Refactor votepower Roster, simplify aggregation of network wide rosters
* [votepower][shard] Adjust roster, optimize usage of BLSPublicKey as key, use MarshalText trick
* [shard] Granular errors
* [votepower][validator] Unify votepower data structure with off-chain usage
* [votepower][consensus][validator] Further simplify and unify votepower with off-chain, validator stats
* [votepower] Use RJs naming convention group,overall
* [votepower] Remove Println, do keep enforcing order
* [effective][reward] Expand semantics of eligibility as it was overloaded and confusing, evict old voting power computations
* [apr] Adjust json field name
* [votepower] Only aggregate on external validator
* [votepower] Mistake on aggregation, custom presentation network-wide
* [rpc][validator][availability] Remove parameter, take into account empty snapshot
* [apr] Use snapshots from two, one epochs ago. Still have question on header
* [apr] Use GetHeaderByNumber for the header needed for time stamp
* [chain] Evict > 3 epoch old voting power
* [blockchain] Leave Delete Validator snapshot as TODO
* [validator][rpc][effective] Undo changes to Protocol field, use virtual construct at RPC layer for meaning
* [project] Address PR comments
* [committee][rpc] Move +1 to computation of epos round rather than hack mutation
* [reward] Remove entire unnecessary loop, hook on AddReward. Remove unnecessary new big int
* [votepower][rpc][validator] Stick with numeric.Dec for token involved with computation, expose accumulate block-reward in RPC
* [effective][committee] Track the candidates for the EPoS auction, RPC median-stake benefits
* [node] Add hack way to get real error reason of why cannot load shardchain
* [consensus] Expand log on current issue on nil block
* [apr] Do the actual call to compute for validator's APR
* [committee] Wrap SlotOrder with validator address, manifests in median-stake RPC
* [apr] Incorrect error handle order
* [quorum] Remove incorrect compare on bls Key, (typo), remove redundant error check
* [shard] Add log if stakedSlots is 0
* [apr] More sanity check on div by zero, more lenient on error when dont have historical data yet
* [committee] Remove + 1 on seat count
* [apr] Use int64() directly
* [apr] Log when odd empty nil header
* [apr] Do not crash on empty header, figure out later
5 years ago
|
|
|
pubKeys, _ := committeeToSet.BLSPublicKeys()
|
|
|
|
|
|
|
|
consensus.getLogger().Info().
|
|
|
|
Int("numPubKeys", len(pubKeys)).
|
|
|
|
Msg("[UpdateConsensusInformation] Successfully updated public keys")
|
|
|
|
consensus.updatePublicKeys(pubKeys, shard.Schedule.InstanceForEpoch(nextEpoch).ExternalAllowlist())
|
|
|
|
|
|
|
|
// Update voters in the committee
|
|
|
|
if _, err := consensus.Decider.SetVoters(
|
|
|
|
committeeToSet, epochToSet,
|
|
|
|
); err != nil {
|
|
|
|
consensus.getLogger().Error().
|
|
|
|
Err(err).
|
|
|
|
Uint32("shard", consensus.ShardID).
|
|
|
|
Msg("Error when updating voters")
|
|
|
|
return Syncing
|
|
|
|
}
|
|
|
|
|
|
|
|
// take care of possible leader change during the epoch
|
|
|
|
// TODO: in a very rare case, when a M1 view change happened, the block contains coinbase for last leader
|
|
|
|
// but the new leader is actually recognized by most of the nodes. At this time, if a node sync to this
|
|
|
|
// exact block and set its leader, it will set with the failed leader as in the coinbase of the block.
|
|
|
|
// This is a very rare case scenario and not likely to cause any issue in mainnet. But we need to think about
|
|
|
|
// a solution to take care of this case because the coinbase of the latest block doesn't really represent the
|
|
|
|
// the real current leader in case of M1 view change.
|
|
|
|
if !curHeader.IsLastBlockInEpoch() && curHeader.Number().Uint64() != 0 {
|
|
|
|
leaderPubKey, err := chain.GetLeaderPubKeyFromCoinbase(consensus.Blockchain(), curHeader)
|
|
|
|
if err != nil || leaderPubKey == nil {
|
|
|
|
consensus.getLogger().Error().Err(err).
|
|
|
|
Msg("[UpdateConsensusInformation] Unable to get leaderPubKey from coinbase")
|
|
|
|
consensus.IgnoreViewIDCheck.Set()
|
|
|
|
hasError = true
|
|
|
|
} else {
|
|
|
|
consensus.getLogger().Info().
|
|
|
|
Str("leaderPubKey", leaderPubKey.Bytes.Hex()).
|
|
|
|
Msg("[UpdateConsensusInformation] Most Recent LeaderPubKey Updated Based on BlockChain")
|
|
|
|
consensus.LeaderPubKey = leaderPubKey
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, key := range pubKeys {
|
|
|
|
// in committee
|
|
|
|
myPubKeys := consensus.getPublicKeys()
|
|
|
|
if myPubKeys.Contains(key.Object) {
|
|
|
|
if hasError {
|
|
|
|
consensus.getLogger().Error().
|
|
|
|
Str("myKey", myPubKeys.SerializeToHexStr()).
|
|
|
|
Msg("[UpdateConsensusInformation] hasError")
|
|
|
|
|
|
|
|
return Syncing
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the leader changed and I myself become the leader
|
|
|
|
if (oldLeader != nil && consensus.LeaderPubKey != nil &&
|
|
|
|
!consensus.LeaderPubKey.Object.IsEqual(oldLeader.Object)) && consensus.isLeader() {
|
|
|
|
go func() {
|
|
|
|
consensus.GetLogger().Info().
|
|
|
|
Str("myKey", myPubKeys.SerializeToHexStr()).
|
|
|
|
Msg("[UpdateConsensusInformation] I am the New Leader")
|
|
|
|
consensus.ReadySignal(SyncProposal)
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
return Normal
|
|
|
|
}
|
|
|
|
}
|
|
|
|
consensus.getLogger().Info().
|
|
|
|
Msg("[UpdateConsensusInformation] not in committee, Listening")
|
|
|
|
|
|
|
|
// not in committee
|
|
|
|
return Listening
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsLeader check if the node is a leader or not by comparing the public key of
|
|
|
|
// the node with the leader public key
|
|
|
|
func (consensus *Consensus) IsLeader() bool {
|
|
|
|
consensus.mutex.RLock()
|
|
|
|
defer consensus.mutex.RUnlock()
|
|
|
|
|
|
|
|
return consensus.isLeader()
|
|
|
|
}
|
|
|
|
|
|
|
|
// isLeader check if the node is a leader or not by comparing the public key of
|
|
|
|
// the node with the leader public key. This function assume it runs under lock.
|
|
|
|
func (consensus *Consensus) isLeader() bool {
|
|
|
|
obj := consensus.LeaderPubKey.Object
|
|
|
|
for _, key := range consensus.priKey {
|
|
|
|
if key.Pub.Object.IsEqual(obj) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetViewIDs set both current view ID and view changing ID to the height
|
|
|
|
// of the blockchain. It is used during client startup to recover the state
|
|
|
|
func (consensus *Consensus) SetViewIDs(height uint64) {
|
|
|
|
consensus.mutex.Lock()
|
|
|
|
defer consensus.mutex.Unlock()
|
|
|
|
consensus.setViewIDs(height)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetViewIDs set both current view ID and view changing ID to the height
|
|
|
|
// of the blockchain. It is used during client startup to recover the state
|
|
|
|
func (consensus *Consensus) setViewIDs(height uint64) {
|
|
|
|
consensus.setCurBlockViewID(height)
|
|
|
|
consensus.setViewChangingID(height)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetCurBlockViewID set the current view ID
|
|
|
|
func (consensus *Consensus) SetCurBlockViewID(viewID uint64) uint64 {
|
|
|
|
return consensus.current.SetCurBlockViewID(viewID)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetCurBlockViewID set the current view ID
|
|
|
|
func (consensus *Consensus) setCurBlockViewID(viewID uint64) {
|
|
|
|
consensus.current.SetCurBlockViewID(viewID)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetViewChangingID set the current view change ID
|
|
|
|
func (consensus *Consensus) SetViewChangingID(viewID uint64) {
|
|
|
|
consensus.current.SetViewChangingID(viewID)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetViewChangingID set the current view change ID
|
|
|
|
func (consensus *Consensus) setViewChangingID(viewID uint64) {
|
|
|
|
consensus.current.SetViewChangingID(viewID)
|
|
|
|
}
|
|
|
|
|
|
|
|
// StartFinalityCount set the finality counter to current time
|
|
|
|
func (consensus *Consensus) StartFinalityCount() {
|
|
|
|
consensus.finalityCounter.Store(time.Now().UnixNano())
|
|
|
|
}
|
|
|
|
|
|
|
|
// FinishFinalityCount calculate the current finality
|
|
|
|
func (consensus *Consensus) FinishFinalityCount() {
|
|
|
|
d := time.Now().UnixNano()
|
chore: merge `main` into `dev` (#4415)
* Mainnet Release Candidate 2023.1.2 (#4376)
* remove default timeouts
* store the evm call timeout in rosetta object
* [cmd] actually apply ToRPCServerConfig
* Removed unused method.
* Rotate external leaders on non-beacon chains.
* Fix nil panic.
* Bump github.com/aws/aws-sdk-go from 1.33.0 to 1.34.0
Bumps [github.com/aws/aws-sdk-go](https://github.com/aws/aws-sdk-go) from 1.33.0 to 1.34.0.
- [Release notes](https://github.com/aws/aws-sdk-go/releases)
- [Changelog](https://github.com/aws/aws-sdk-go/blob/v1.34.0/CHANGELOG.md)
- [Commits](https://github.com/aws/aws-sdk-go/compare/v1.33.0...v1.34.0)
---
updated-dependencies:
- dependency-name: github.com/aws/aws-sdk-go
dependency-type: direct:production
...
Signed-off-by: dependabot[bot] <support@github.com>
* Bump github.com/ipld/go-ipld-prime from 0.9.0 to 0.19.0
Bumps [github.com/ipld/go-ipld-prime](https://github.com/ipld/go-ipld-prime) from 0.9.0 to 0.19.0.
- [Release notes](https://github.com/ipld/go-ipld-prime/releases)
- [Changelog](https://github.com/ipld/go-ipld-prime/blob/master/CHANGELOG.md)
- [Commits](https://github.com/ipld/go-ipld-prime/compare/v0.9.0...v0.19.0)
---
updated-dependencies:
- dependency-name: github.com/ipld/go-ipld-prime
dependency-type: indirect
...
Signed-off-by: dependabot[bot] <support@github.com>
* Bump golang.org/x/net from 0.3.0 to 0.7.0
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.3.0 to 0.7.0.
- [Release notes](https://github.com/golang/net/releases)
- [Commits](https://github.com/golang/net/compare/v0.3.0...v0.7.0)
---
updated-dependencies:
- dependency-name: golang.org/x/net
dependency-type: indirect
...
Signed-off-by: dependabot[bot] <support@github.com>
* Small fixes.
* in progress.
* in progress.
* in progress.
* consensus check is forked
* update master
* fix leader
* check leader for N blocks
* fix
* fix
* Cleanup and fix update pub keys.
* Rotate leader.
* fix
fix
fix
fix
fix
* Cleaned.
* Cache for `GetLeaderPubKeyFromCoinbase`, removed `NthNextHmyExt`.
* activate epoch
* comment activation
* 295 epoch
* Fix failed tests.
* Fixed code review.
* Fix review "--port flag".
* Fix review comments.
* Returned locks in rotateLeader.
* Rebased onto dev.
* Commented golangci.
* staged stream sync v1.0
* fix protocol tests
* fix spell
* remove unused struct
* fix rosetta test
* add comments and refactor verify sig
* add comments, remove extra function
* add comment
* refactor errors, rename metrics
* refactor p2p host creation
* fix initsync and host creation
* fix short range hash chain
* fix beacon node detection for p2p protocol
* refactor stream peer cooldown and fix protocol beacon node field
* refactor p2p host and routing
* fix p2p discovery test issue
* add MaxAdvertiseWaitTime to handle advertisements interval and address stream connection issue
* terminal print the peer id and proto id
* fix boot complete message when node is shut down
* add new config option ( ForceReachabilityPublic ) to fix local-net consensus issue
* fix self query issue
* fix test NewDNSSyncingPeerProvider
* [testnet] disable leader rotation
* fix discovery issue for legacy sync
* add watermark low/high options for p2p connection manager
* add test for new conn manager flags
* fix dedent
* add comment to inform about p2p connection manager options
* fix max height issue
* add a separate log for get max height error
* fix log
* feat: triesInMemory flag
* fix: panic if TriesInMemory is 1 to 2
* in progress.
* consensus check is forked
* fix
* Cleanup and fix update pub keys.
* fix
fix
fix
fix
fix
* activate epoch
* EpochTBD for leader rotation epoch.
* 295 epoch
* Decider no longer requires public keys as a dependency. (#4289)
* Consensus doesn't require anymore `Node` as a circular dependency.
* Proper blockchain initialization.
* Rwlock consensus.
* Removed channels.
* Removed view change locks.
* Removed timers locks.
* Removed fbft locks.
* Removed multiSigMutex locks.
* Removed leader locks.
* Removed additional locks and isViewChange.
* Added locks detected by race.
* Added locks detected by race.
* Locks for start.
* Removed additional logs.
* Removed additional locks.
* Removed additional locks.
* Make func private.
* Make VerifyBlock private.
* Make IsLeader private.
* Make ParseFBFTMessage private.
* Fix remove locks.
* Added additional locks.
* Added additional locks.
* Added readSignatureBitmapPayload locks.
* Added HandleMessageUpdate locks.
* Added LastMile locks.
* Locks for IsValidatorInCommittee.
* Fixed locks.
* Fixed tests.
* Fixed tests.
* Fixed lock.
* Rebased over leader rotation.
* Fix formatting.
* Rebased onto dev.
* in progress.
* consensus check is forked
* update master
* fix leader
* check leader for N blocks
* fix
* fix
* Cleanup and fix update pub keys.
* Rotate leader.
* fix
fix
fix
fix
fix
* Cleaned.
* Cache for `GetLeaderPubKeyFromCoinbase`, removed `NthNextHmyExt`.
* comment activation
* 295 epoch
* Fix failed tests.
* Fixed code review.
* Fix review comments.
* Merged leader rotation.
* Rebased on dev.
* Rebased on dev.
* Fix usage of private methods.
* Fix usage of private methods.
* Fix usage of private methods.
* Removed deadcode, LockedFBFTPhase.
* Fix review comment.
* Fix review comment.
* Go mod tidy.
* Set to EpochTBD.
* Fix tests.
* [core] fix state handling of self destruct
If a contract self destructs to self and then receives funds within the
same transaction, it is possible for its stale state to be saved. This
change removes that possibility by checking for deleted state objects
before returning them.
* Fixed race error.
* rpc: add configurable http and `eth_call` timeout
* remove default timeouts
* store the evm call timeout in rosetta object
* [cmd] actually apply ToRPCServerConfig
* Removed unused method.
* Rotate external leaders on non-beacon chains.
* Fix nil panic.
* in progress.
* in progress.
* in progress.
* consensus check is forked
* update master
* fix leader
* check leader for N blocks
* fix
* fix
* Cleanup and fix update pub keys.
* Rotate leader.
* fix
fix
fix
fix
fix
* Cleaned.
* Cache for `GetLeaderPubKeyFromCoinbase`, removed `NthNextHmyExt`.
* Fixed code review.
* Fix review comments.
* Returned locks in rotateLeader.
* Rebased onto dev.
* staged stream sync v1.0
* refactor errors, rename metrics
* fix p2p discovery test issue
* add watermark low/high options for p2p connection manager
* fix dedent
* in progress.
* consensus check is forked
* fix
* Cleanup and fix update pub keys.
* fix
fix
fix
fix
fix
* activate epoch
* EpochTBD for leader rotation epoch.
* 295 epoch
* Decider no longer requires public keys as a dependency. (#4289)
* Consensus doesn't require anymore `Node` as a circular dependency.
* Proper blockchain initialization.
* Rwlock consensus.
* Removed channels.
* Removed view change locks.
* Removed multiSigMutex locks.
* Removed leader locks.
* Removed additional locks and isViewChange.
* Added locks detected by race.
* Added locks detected by race.
* Locks for start.
* Removed additional locks.
* Removed additional locks.
* Make func private.
* Make VerifyBlock private.
* Make IsLeader private.
* Make ParseFBFTMessage private.
* Fix remove locks.
* Added additional locks.
* Added additional locks.
* Added readSignatureBitmapPayload locks.
* Added HandleMessageUpdate locks.
* Added LastMile locks.
* Locks for IsValidatorInCommittee.
* Fixed locks.
* Fixed tests.
* Fixed lock.
* Rebased over leader rotation.
* in progress.
* consensus check is forked
* update master
* fix leader
* check leader for N blocks
* fix
* fix
* Cleanup and fix update pub keys.
* Rotate leader.
* fix
fix
fix
fix
fix
* Cleaned.
* Cache for `GetLeaderPubKeyFromCoinbase`, removed `NthNextHmyExt`.
* Fix failed tests.
* Fixed code review.
* Fix review comments.
* Merged leader rotation.
* Rebased on dev.
* Rebased on dev.
* Fix usage of private methods.
* Fix usage of private methods.
* Fix usage of private methods.
* Removed deadcode, LockedFBFTPhase.
* Fix review comment.
* Go mod tidy.
* remove default timeouts
* Rotate external leaders on non-beacon chains.
* Fix nil panic.
* Fixes.
* Update singleton.go
* evm: don't return extcode for validators
Due to technical debt, validator information is stored in the code field
of the address. The code field can be accessed in Solidity for an
arbitrary address using `extcodesize`, `extcodehash`, and `extcodecopy`
or helper commands (such as `address.code.Length`). The presence of this
field is used by contract developers to (erroneously) deny smart
contract access to other smart contracts (and therefore, validators).
This PR fixes that oversight by returning the same values as other EOAs
for known validator addresses. Obviously, it needs a hard fork that will
be scheduled separately.
* Fix context passing.
* Clean up code.
* Removed engine dependency.
* Fix possible panic.
* Clean up code.
* Network type.
* Fix tests.
* Revert "Removed engine dependency." (#4392)
* Revert "Fix tests."
This reverts commit 597ba2d6f1ed54ff599b9d9b8940c7285ab1277a.
* Revert "Network type."
This reverts commit 5e1878aedca3989dc0f34161dae1833e43ca6a76.
* Revert "Clean up code."
This reverts commit 15885f4c9b9263746827172b4f4f56d0926d18e2.
* Revert "Fix possible panic."
This reverts commit 1a70d5eb66cdbf8a23791806b71a323eed320085.
* Revert "Removed engine dependency."
This reverts commit 8c2ff803f709f944cfc8b1278f35cf5b2cacf859.
* gitignore the cache folder (#4389)
* stable localnet with external validator (#4388)
* stable localnet with external validator
* ignore deploy config file comments
* reduce node launched in localnet
* update makefile
* localnet configuration - add more fn
* fix validator information command typo
---------
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: MaxMustermann2 <82761650+MaxMustermann2@users.noreply.github.com>
Co-authored-by: frozen <355847+Frozen@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: “GheisMohammadi” <“Gheis.Mohammadi@gmail.com”>
Co-authored-by: “GheisMohammadi” <36589218+GheisMohammadi@users.noreply.github.com>
Co-authored-by: Sun Hyuk Ahn <sunhyukahn@Suns-MacBook-Pro.local>
Co-authored-by: Soph <35721420+sophoah@users.noreply.github.com>
* build: update pinned curl version (#4394)
Per the Alpine Linux package repositories, the version for cURL included
with v3.16 has changed to revision 6
* consensus: replace type assert with test (#4398)
If `consensus.finalityCounter` does not have anything stored (for
example in Syncing mode), the `Load()` returns an interface that cannot
be automatically asserted to an `int64`. This results in the node
crashing. This commit fixes that.
* Turn pprof default on with local saved files (#3894)
* Turn pprof default on with local saved files
* [pprof] change interval from 600s to 3600s
* Revert "Turn pprof default on with local saved files (#3894)" (#4400)
This reverts commit 78d26d7910a58ded3bfe689b3de07ea28d95d7d5.
---------
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Casey Gardiner <117784577+ONECasey@users.noreply.github.com>
Co-authored-by: frozen <355847+Frozen@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: “GheisMohammadi” <“Gheis.Mohammadi@gmail.com”>
Co-authored-by: “GheisMohammadi” <36589218+GheisMohammadi@users.noreply.github.com>
Co-authored-by: Sun Hyuk Ahn <sunhyukahn@Suns-MacBook-Pro.local>
Co-authored-by: Soph <35721420+sophoah@users.noreply.github.com>
Co-authored-by: Jacky Wang <jackyw.se@gmail.com>
2 years ago
|
|
|
if prior, ok := consensus.finalityCounter.Load().(int64); ok {
|
|
|
|
consensus.finality = (d - prior) / 1000000
|
|
|
|
consensusFinalityHistogram.Observe(float64(consensus.finality))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetFinality returns the finality time in milliseconds of previous consensus
|
|
|
|
func (consensus *Consensus) GetFinality() int64 {
|
|
|
|
return consensus.finality
|
|
|
|
}
|
|
|
|
|
|
|
|
// switchPhase will switch FBFTPhase to desired phase.
|
|
|
|
func (consensus *Consensus) switchPhase(subject string, desired FBFTPhase) {
|
|
|
|
consensus.getLogger().Info().
|
|
|
|
Str("from:", consensus.phase.String()).
|
|
|
|
Str("to:", desired.String()).
|
|
|
|
Str("switchPhase:", subject)
|
|
|
|
|
|
|
|
consensus.phase = desired
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
errGetPreparedBlock = errors.New("failed to get prepared block for self commit")
|
|
|
|
errReadBitmapPayload = errors.New("failed to read signature bitmap payload")
|
|
|
|
)
|
|
|
|
|
|
|
|
// selfCommit will create a commit message and commit it locally
|
|
|
|
// it is used by the new leadder of the view change routine
|
|
|
|
// when view change is succeeded and the new leader
|
|
|
|
// received prepared payload from other validators or from local
|
|
|
|
func (consensus *Consensus) selfCommit(payload []byte) error {
|
|
|
|
var blockHash [32]byte
|
|
|
|
copy(blockHash[:], payload[:32])
|
|
|
|
|
|
|
|
// Leader sign and add commit message
|
|
|
|
block := consensus.fBFTLog.GetBlockByHash(blockHash)
|
|
|
|
if block == nil {
|
|
|
|
return errGetPreparedBlock
|
|
|
|
}
|
|
|
|
|
|
|
|
aggSig, mask, err := consensus.readSignatureBitmapPayload(payload, 32, consensus.Decider.Participants())
|
|
|
|
if err != nil {
|
|
|
|
return errReadBitmapPayload
|
|
|
|
}
|
|
|
|
|
|
|
|
// Have to keep the block hash so the leader can finish the commit phase of prepared block
|
|
|
|
consensus.resetState()
|
|
|
|
|
|
|
|
copy(consensus.blockHash[:], blockHash[:])
|
|
|
|
consensus.switchPhase("selfCommit", FBFTCommit)
|
|
|
|
consensus.aggregatedPrepareSig = aggSig
|
|
|
|
consensus.prepareBitmap = mask
|
|
|
|
commitPayload := signature.ConstructCommitPayload(consensus.ChainReader().Config(),
|
|
|
|
block.Epoch(), block.Hash(), block.NumberU64(), block.Header().ViewID().Uint64())
|
|
|
|
for i, key := range consensus.priKey {
|
|
|
|
if err := consensus.commitBitmap.SetKey(key.Pub.Bytes, true); err != nil {
|
|
|
|
consensus.getLogger().Error().
|
|
|
|
Err(err).
|
|
|
|
Int("Index", i).
|
|
|
|
Str("Key", key.Pub.Bytes.Hex()).
|
|
|
|
Msg("[selfCommit] New Leader commit bitmap set failed")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := consensus.Decider.AddNewVote(
|
|
|
|
quorum.Commit,
|
|
|
|
[]*bls_cosi.PublicKeyWrapper{key.Pub},
|
|
|
|
key.Pri.SignHash(commitPayload),
|
|
|
|
common.BytesToHash(consensus.blockHash[:]),
|
|
|
|
block.NumberU64(),
|
|
|
|
block.Header().ViewID().Uint64(),
|
|
|
|
); err != nil {
|
|
|
|
consensus.getLogger().Warn().
|
|
|
|
Err(err).
|
|
|
|
Int("Index", i).
|
|
|
|
Str("Key", key.Pub.Bytes.Hex()).
|
|
|
|
Msg("[selfCommit] submit vote on viewchange commit failed")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// NumSignaturesIncludedInBlock returns the number of signatures included in the block
|
|
|
|
func (consensus *Consensus) NumSignaturesIncludedInBlock(block *types.Block) uint32 {
|
|
|
|
count := uint32(0)
|
|
|
|
members := consensus.Decider.Participants()
|
|
|
|
// TODO(audit): do not reconstruct the Mask
|
|
|
|
mask := bls.NewMask(members)
|
|
|
|
err := mask.SetMask(block.Header().LastCommitBitmap())
|
|
|
|
if err != nil {
|
|
|
|
return count
|
|
|
|
}
|
|
|
|
for _, key := range consensus.GetPublicKeys() {
|
|
|
|
if ok, err := mask.KeyEnabled(key.Bytes); err == nil && ok {
|
|
|
|
count++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return count
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetLogger returns logger for consensus contexts added.
|
|
|
|
func (consensus *Consensus) GetLogger() *zerolog.Logger {
|
|
|
|
consensus.mutex.RLock()
|
|
|
|
defer consensus.mutex.RUnlock()
|
|
|
|
return consensus.getLogger()
|
|
|
|
}
|
|
|
|
|
|
|
|
// getLogger returns logger for consensus contexts added
|
|
|
|
func (consensus *Consensus) getLogger() *zerolog.Logger {
|
|
|
|
logger := utils.Logger().With().
|
|
|
|
Uint64("myBlock", consensus.blockNum).
|
|
|
|
Uint64("myViewID", consensus.getCurBlockViewID()).
|
|
|
|
Str("phase", consensus.phase.String()).
|
|
|
|
Str("mode", consensus.current.Mode().String()).
|
|
|
|
Logger()
|
|
|
|
return &logger
|
|
|
|
}
|
|
|
|
|
|
|
|
// VerifyNewBlock is called by consensus participants to verify the block (account model) they are
|
|
|
|
// running consensus on.
|
|
|
|
func VerifyNewBlock(hooks *webhooks.Hooks, blockChain core.BlockChain, beaconChain core.BlockChain) func(*types.Block) error {
|
|
|
|
return func(newBlock *types.Block) error {
|
|
|
|
if err := blockChain.ValidateNewBlock(newBlock, beaconChain); err != nil {
|
|
|
|
if hooks := hooks; hooks != nil {
|
|
|
|
if p := hooks.ProtocolIssues; p != nil {
|
|
|
|
url := p.OnCannotCommit
|
|
|
|
go func() {
|
|
|
|
webhooks.DoPost(url, map[string]interface{}{
|
|
|
|
"bad-header": newBlock.Header(),
|
|
|
|
"reason": err.Error(),
|
|
|
|
})
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
utils.Logger().Error().
|
|
|
|
Str("blockHash", newBlock.Hash().Hex()).
|
|
|
|
Int("numTx", len(newBlock.Transactions())).
|
|
|
|
Int("numStakingTx", len(newBlock.StakingTransactions())).
|
|
|
|
Err(err).
|
|
|
|
Msgf("[VerifyNewBlock] Cannot Verify New Block!!!, blockHeight %d, myHeight %d", newBlock.NumberU64(), blockChain.CurrentHeader().NumberU64())
|
|
|
|
return errors.Errorf(
|
|
|
|
"[VerifyNewBlock] Cannot Verify New Block!!! block-hash %s txn-count %d",
|
|
|
|
newBlock.Hash().Hex(),
|
|
|
|
len(newBlock.Transactions()),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|