|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"math/big"
|
|
|
|
"unsafe"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
|
|
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
|
|
|
"github.com/ethereum/go-ethereum/rlp"
|
|
|
|
blockif "github.com/woop-chain/woop/block/interface"
|
|
|
|
"github.com/woop-chain/woop/crypto/hash"
|
|
|
|
"github.com/woop-chain/woop/internal/utils"
|
|
|
|
"github.com/woop-chain/woop/shard"
|
|
|
|
"github.com/rs/zerolog"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Header is the V1 block header.
|
|
|
|
type Header struct {
|
|
|
|
fields headerFields
|
|
|
|
}
|
|
|
|
|
|
|
|
// EncodeRLP encodes the header fields into RLP format.
|
|
|
|
func (h *Header) EncodeRLP(w io.Writer) error {
|
|
|
|
return rlp.Encode(w, &h.fields)
|
|
|
|
}
|
|
|
|
|
|
|
|
// DecodeRLP decodes the given RLP decode stream into the header fields.
|
|
|
|
func (h *Header) DecodeRLP(s *rlp.Stream) error {
|
|
|
|
return s.Decode(&h.fields)
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewHeader creates a new header object.
|
|
|
|
func NewHeader() *Header {
|
|
|
|
return &Header{headerFields{
|
|
|
|
Number: new(big.Int),
|
|
|
|
Time: new(big.Int),
|
|
|
|
ViewID: new(big.Int),
|
|
|
|
Epoch: new(big.Int),
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
type headerFields struct {
|
|
|
|
ParentHash common.Hash `json:"parentHash" gencodec:"required"`
|
|
|
|
Coinbase common.Address `json:"miner" gencodec:"required"`
|
|
|
|
Root common.Hash `json:"stateRoot" gencodec:"required"`
|
|
|
|
TxHash common.Hash `json:"transactionsRoot" gencodec:"required"`
|
|
|
|
ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"`
|
|
|
|
OutgoingReceiptHash common.Hash `json:"outgoingReceiptsRoot" gencodec:"required"`
|
|
|
|
IncomingReceiptHash common.Hash `json:"incomingReceiptsRoot" gencodec:"required"`
|
|
|
|
Bloom ethtypes.Bloom `json:"logsBloom" gencodec:"required"`
|
|
|
|
Number *big.Int `json:"number" gencodec:"required"`
|
|
|
|
GasLimit uint64 `json:"gasLimit" gencodec:"required"`
|
|
|
|
GasUsed uint64 `json:"gasUsed" gencodec:"required"`
|
|
|
|
Time *big.Int `json:"timestamp" gencodec:"required"`
|
|
|
|
Extra []byte `json:"extraData" gencodec:"required"`
|
|
|
|
MixDigest common.Hash `json:"mixHash" gencodec:"required"`
|
|
|
|
// Additional Fields
|
|
|
|
ViewID *big.Int `json:"viewID" gencodec:"required"`
|
|
|
|
Epoch *big.Int `json:"epoch" gencodec:"required"`
|
|
|
|
ShardID uint32 `json:"shardID" gencodec:"required"`
|
|
|
|
LastCommitSignature [96]byte `json:"lastCommitSignature" gencodec:"required"`
|
|
|
|
LastCommitBitmap []byte `json:"lastCommitBitmap" gencodec:"required"` // Contains which validator signed
|
|
|
|
ShardStateHash common.Hash `json:"shardStateRoot"`
|
|
|
|
Vrf []byte `json:"vrf"`
|
|
|
|
Vdf []byte `json:"vdf"`
|
|
|
|
ShardState []byte `json:"shardState"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ParentHash is the header hash of the parent block. For the genesis block
|
|
|
|
// which has no parent by definition, this field is zeroed out.
|
|
|
|
func (h *Header) ParentHash() common.Hash {
|
|
|
|
return h.fields.ParentHash
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetParentHash sets the parent hash field.
|
|
|
|
func (h *Header) SetParentHash(newParentHash common.Hash) {
|
|
|
|
h.fields.ParentHash = newParentHash
|
|
|
|
}
|
|
|
|
|
|
|
|
// Coinbase is the address of the node that proposed this block and all
|
|
|
|
// transactions in it.
|
|
|
|
func (h *Header) Coinbase() common.Address {
|
|
|
|
return h.fields.Coinbase
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetCoinbase sets the coinbase address field.
|
|
|
|
func (h *Header) SetCoinbase(newCoinbase common.Address) {
|
|
|
|
h.fields.Coinbase = newCoinbase
|
|
|
|
}
|
|
|
|
|
|
|
|
// Root is the state (account) trie root hash.
|
|
|
|
func (h *Header) Root() common.Hash {
|
|
|
|
return h.fields.Root
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetRoot sets the state trie root hash field.
|
|
|
|
func (h *Header) SetRoot(newRoot common.Hash) {
|
|
|
|
h.fields.Root = newRoot
|
|
|
|
}
|
|
|
|
|
|
|
|
// TxHash is the transaction trie root hash.
|
|
|
|
func (h *Header) TxHash() common.Hash {
|
|
|
|
return h.fields.TxHash
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetTxHash sets the transaction trie root hash field.
|
|
|
|
func (h *Header) SetTxHash(newTxHash common.Hash) {
|
|
|
|
h.fields.TxHash = newTxHash
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReceiptHash is the same-shard transaction receipt trie hash.
|
|
|
|
func (h *Header) ReceiptHash() common.Hash {
|
|
|
|
return h.fields.ReceiptHash
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetReceiptHash sets the same-shard transaction receipt trie hash.
|
|
|
|
func (h *Header) SetReceiptHash(newReceiptHash common.Hash) {
|
|
|
|
h.fields.ReceiptHash = newReceiptHash
|
|
|
|
}
|
|
|
|
|
|
|
|
// OutgoingReceiptHash is the egress transaction receipt trie hash.
|
|
|
|
func (h *Header) OutgoingReceiptHash() common.Hash {
|
|
|
|
return h.fields.OutgoingReceiptHash
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetOutgoingReceiptHash sets the egress transaction receipt trie hash.
|
|
|
|
func (h *Header) SetOutgoingReceiptHash(newOutgoingReceiptHash common.Hash) {
|
|
|
|
h.fields.OutgoingReceiptHash = newOutgoingReceiptHash
|
|
|
|
}
|
|
|
|
|
|
|
|
// IncomingReceiptHash is the ingress transaction receipt trie hash.
|
|
|
|
func (h *Header) IncomingReceiptHash() common.Hash {
|
|
|
|
return h.fields.IncomingReceiptHash
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetIncomingReceiptHash sets the ingress transaction receipt trie hash.
|
|
|
|
func (h *Header) SetIncomingReceiptHash(newIncomingReceiptHash common.Hash) {
|
|
|
|
h.fields.IncomingReceiptHash = newIncomingReceiptHash
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bloom is the Bloom filter that indexes accounts and topics logged by smart
|
|
|
|
// contract transactions (executions) in this block.
|
|
|
|
func (h *Header) Bloom() ethtypes.Bloom {
|
|
|
|
return h.fields.Bloom
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetBloom sets the smart contract log Bloom filter for this block.
|
|
|
|
func (h *Header) SetBloom(newBloom ethtypes.Bloom) {
|
|
|
|
h.fields.Bloom = newBloom
|
|
|
|
}
|
|
|
|
|
|
|
|
// Number is the block number.
|
|
|
|
//
|
|
|
|
// The returned instance is a copy; the caller may do anything with it.
|
|
|
|
func (h *Header) Number() *big.Int {
|
|
|
|
return new(big.Int).Set(h.fields.Number)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetNumber sets the block number.
|
|
|
|
//
|
|
|
|
// It stores a copy; the caller may freely modify the original.
|
|
|
|
func (h *Header) SetNumber(newNumber *big.Int) {
|
|
|
|
h.fields.Number = new(big.Int).Set(newNumber)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GasLimit is the gas limit for transactions in this block.
|
|
|
|
func (h *Header) GasLimit() uint64 {
|
|
|
|
return h.fields.GasLimit
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetGasLimit sets the gas limit for transactions in this block.
|
|
|
|
func (h *Header) SetGasLimit(newGasLimit uint64) {
|
|
|
|
h.fields.GasLimit = newGasLimit
|
|
|
|
}
|
|
|
|
|
|
|
|
// GasUsed is the amount of gas used by transactions in this block.
|
|
|
|
func (h *Header) GasUsed() uint64 {
|
|
|
|
return h.fields.GasUsed
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetGasUsed sets the amount of gas used by transactions in this block.
|
|
|
|
func (h *Header) SetGasUsed(newGasUsed uint64) {
|
|
|
|
h.fields.GasUsed = newGasUsed
|
|
|
|
}
|
|
|
|
|
|
|
|
// Time is the UNIX timestamp of this block.
|
|
|
|
//
|
|
|
|
// The returned instance is a copy; the caller may do anything with it.
|
|
|
|
func (h *Header) Time() *big.Int {
|
|
|
|
return new(big.Int).Set(h.fields.Time)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetTime sets the UNIX timestamp of this block.
|
|
|
|
//
|
|
|
|
// It stores a copy; the caller may freely modify the original.
|
|
|
|
func (h *Header) SetTime(newTime *big.Int) {
|
|
|
|
h.fields.Time = new(big.Int).Set(newTime)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Extra is the extra data field of this block.
|
|
|
|
//
|
|
|
|
// The returned slice is a copy; the caller may do anything with it.
|
|
|
|
func (h *Header) Extra() []byte {
|
|
|
|
return append(h.fields.Extra[:0:0], h.fields.Extra...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetExtra sets the extra data field of this block.
|
|
|
|
//
|
|
|
|
// It stores a copy; the caller may freely modify the original.
|
|
|
|
func (h *Header) SetExtra(newExtra []byte) {
|
|
|
|
h.fields.Extra = append(newExtra[:0:0], newExtra...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// MixDigest is the mixhash.
|
|
|
|
//
|
|
|
|
// This field is a remnant from Ethereum, and Woop does not use it and always
|
|
|
|
// zeroes it out.
|
|
|
|
func (h *Header) MixDigest() common.Hash {
|
|
|
|
return h.fields.MixDigest
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetMixDigest sets the mixhash of this block.
|
|
|
|
func (h *Header) SetMixDigest(newMixDigest common.Hash) {
|
|
|
|
h.fields.MixDigest = newMixDigest
|
|
|
|
}
|
|
|
|
|
|
|
|
// ViewID is the ID of the view in which this block was originally proposed.
|
|
|
|
//
|
|
|
|
// It normally increases by one for each subsequent block, or by more than one
|
|
|
|
// if one or more PBFT/FBFT view changes have occurred.
|
|
|
|
//
|
|
|
|
// The returned instance is a copy; the caller may do anything with it.
|
|
|
|
func (h *Header) ViewID() *big.Int {
|
|
|
|
return new(big.Int).Set(h.fields.ViewID)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetViewID sets the view ID in which the block was originally proposed.
|
|
|
|
//
|
|
|
|
// It stores a copy; the caller may freely modify the original.
|
|
|
|
func (h *Header) SetViewID(newViewID *big.Int) {
|
|
|
|
h.fields.ViewID = new(big.Int).Set(newViewID)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Epoch is the epoch number of this block.
|
|
|
|
//
|
|
|
|
// The returned instance is a copy; the caller may do anything with it.
|
|
|
|
func (h *Header) Epoch() *big.Int {
|
|
|
|
return new(big.Int).Set(h.fields.Epoch)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetEpoch sets the epoch number of this block.
|
|
|
|
//
|
|
|
|
// It stores a copy; the caller may freely modify the original.
|
|
|
|
func (h *Header) SetEpoch(newEpoch *big.Int) {
|
|
|
|
h.fields.Epoch = new(big.Int).Set(newEpoch)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ShardID is the shard ID to which this block belongs.
|
|
|
|
func (h *Header) ShardID() uint32 {
|
|
|
|
return h.fields.ShardID
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetShardID sets the shard ID to which this block belongs.
|
|
|
|
func (h *Header) SetShardID(newShardID uint32) {
|
|
|
|
h.fields.ShardID = newShardID
|
|
|
|
}
|
|
|
|
|
|
|
|
// LastCommitSignature is the FBFT commit group signature for the last block.
|
|
|
|
func (h *Header) LastCommitSignature() [96]byte {
|
|
|
|
return h.fields.LastCommitSignature
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetLastCommitSignature sets the FBFT commit group signature for the last
|
|
|
|
// block.
|
|
|
|
func (h *Header) SetLastCommitSignature(newLastCommitSignature [96]byte) {
|
|
|
|
h.fields.LastCommitSignature = newLastCommitSignature
|
|
|
|
}
|
|
|
|
|
|
|
|
// LastCommitBitmap is the signatory bitmap of the previous block. Bit
|
|
|
|
// positions index into committee member array.
|
|
|
|
//
|
|
|
|
// The returned slice is a copy; the caller may do anything with it.
|
|
|
|
func (h *Header) LastCommitBitmap() []byte {
|
|
|
|
return append(h.fields.LastCommitBitmap[:0:0], h.fields.LastCommitBitmap...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetLastCommitBitmap sets the signatory bitmap of the previous block.
|
|
|
|
//
|
|
|
|
// It stores a copy; the caller may freely modify the original.
|
|
|
|
func (h *Header) SetLastCommitBitmap(newLastCommitBitmap []byte) {
|
|
|
|
h.fields.LastCommitBitmap = append(newLastCommitBitmap[:0:0], newLastCommitBitmap...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ShardStateHash is the shard state hash.
|
|
|
|
func (h *Header) ShardStateHash() common.Hash {
|
|
|
|
return h.fields.ShardStateHash
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetShardStateHash sets the shard state hash.
|
|
|
|
func (h *Header) SetShardStateHash(newShardStateHash common.Hash) {
|
|
|
|
h.fields.ShardStateHash = newShardStateHash
|
|
|
|
}
|
|
|
|
|
|
|
|
// Vrf is the output of the VRF for the epoch.
|
|
|
|
//
|
|
|
|
// The returned slice is a copy; the caller may do anything with it.
|
|
|
|
func (h *Header) Vrf() []byte {
|
|
|
|
return append(h.fields.Vrf[:0:0], h.fields.Vrf...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetVrf sets the output of the VRF for the epoch.
|
|
|
|
//
|
|
|
|
// It stores a copy; the caller may freely modify the original.
|
|
|
|
func (h *Header) SetVrf(newVrf []byte) {
|
|
|
|
h.fields.Vrf = append(newVrf[:0:0], newVrf...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Vdf is the output of the VDF for the epoch.
|
|
|
|
//
|
|
|
|
// The returned slice is a copy; the caller may do anything with it.
|
|
|
|
func (h *Header) Vdf() []byte {
|
|
|
|
return append(h.fields.Vdf[:0:0], h.fields.Vdf...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetVdf sets the output of the VDF for the epoch.
|
|
|
|
//
|
|
|
|
// It stores a copy; the caller may freely modify the original.
|
|
|
|
func (h *Header) SetVdf(newVdf []byte) {
|
|
|
|
h.fields.Vdf = append(newVdf[:0:0], newVdf...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ShardState is the RLP-encoded form of shard state (list of committees) for
|
|
|
|
// the next epoch.
|
|
|
|
//
|
|
|
|
// The returned slice is a copy; the caller may do anything with it.
|
|
|
|
func (h *Header) ShardState() []byte {
|
|
|
|
return append(h.fields.ShardState[:0:0], h.fields.ShardState...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetShardState sets the RLP-encoded form of shard state
|
|
|
|
//
|
|
|
|
// It stores a copy; the caller may freely modify the original.
|
|
|
|
func (h *Header) SetShardState(newShardState []byte) {
|
|
|
|
h.fields.ShardState = append(newShardState[:0:0], newShardState...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// CrossLinks is the RLP-encoded form of non-beacon block headers chosen to be
|
|
|
|
// canonical by the beacon committee. This field is present only on beacon
|
|
|
|
// chain block headers.
|
|
|
|
//
|
|
|
|
// The returned slice is a copy; the caller may do anything with it.
|
|
|
|
func (h *Header) CrossLinks() []byte {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetCrossLinks sets the RLP-encoded form of non-beacon block headers chosen to
|
|
|
|
// be canonical by the beacon committee.
|
|
|
|
//
|
|
|
|
// It stores a copy; the caller may freely modify the original.
|
|
|
|
func (h *Header) SetCrossLinks(newCrossLinks []byte) {
|
|
|
|
h.Logger(utils.Logger()).Warn().
|
|
|
|
Hex("crossLinks", newCrossLinks).
|
|
|
|
Msg("cannot store cross-chain links in V1 header")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Slashes ..
|
|
|
|
func (h *Header) Slashes() []byte {
|
[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
|
|
|
h.Logger(utils.Logger()).Info().
|
|
|
|
Msg("No slashes in V1 header")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetSlashes ..
|
|
|
|
func (h *Header) SetSlashes(newSlashes []byte) {
|
|
|
|
h.Logger(utils.Logger()).Error().
|
|
|
|
Hex("slashes", newSlashes).
|
|
|
|
Msg("cannot store slashes in V1 header")
|
|
|
|
}
|
|
|
|
|
|
|
|
// field type overrides for gencodec
|
|
|
|
type headerMarshaling struct {
|
|
|
|
Difficulty *hexutil.Big
|
|
|
|
Number *hexutil.Big
|
|
|
|
GasLimit hexutil.Uint64
|
|
|
|
GasUsed hexutil.Uint64
|
|
|
|
Time *hexutil.Big
|
|
|
|
Extra hexutil.Bytes
|
|
|
|
Hash common.Hash `json:"hash"` // adds call to Hash() in MarshalJSON
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hash returns the block hash of the header, which is simply the keccak256 hash of its
|
|
|
|
// RLP encoding.
|
|
|
|
func (h *Header) Hash() common.Hash {
|
|
|
|
return hash.FromRLP(h)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Size returns the approximate memory used by all internal contents. It is used
|
|
|
|
// to approximate and limit the memory consumption of various caches.
|
|
|
|
func (h *Header) Size() common.StorageSize {
|
|
|
|
// TODO: update with new fields
|
|
|
|
return common.StorageSize(unsafe.Sizeof(*h)) + common.StorageSize(len(h.Extra())+(h.Number().BitLen()+h.Time().BitLen())/8)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Logger returns a sub-logger with block contexts added.
|
|
|
|
func (h *Header) Logger(logger *zerolog.Logger) *zerolog.Logger {
|
|
|
|
nlogger := logger.
|
|
|
|
With().
|
|
|
|
Str("blockHash", h.Hash().Hex()).
|
|
|
|
Uint32("blockShard", h.ShardID()).
|
|
|
|
Uint64("blockEpoch", h.Epoch().Uint64()).
|
|
|
|
Uint64("blockNumber", h.Number().Uint64()).
|
|
|
|
Logger()
|
|
|
|
return &nlogger
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetShardState returns the deserialized shard state object.
|
|
|
|
func (h *Header) GetShardState() (shard.State, error) {
|
|
|
|
state, err := shard.DecodeWrapper(h.ShardState())
|
|
|
|
if err != nil {
|
|
|
|
return shard.State{}, err
|
|
|
|
}
|
|
|
|
return *state, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy returns a copy of the given header.
|
|
|
|
func (h *Header) Copy() blockif.Header {
|
|
|
|
cpy := *h
|
|
|
|
return &cpy
|
|
|
|
}
|