Skip to content

Commit

Permalink
Squashed commit of the following: (#2750)
Browse files Browse the repository at this point in the history
commit ba1c0cd
Author: Edgar Aroutiounian <edgar.factorial@gmail.com>
Date:   Sun Apr 5 23:53:03 2020 -0700

    [blockchain] Create fresh big int, remove more dead code from static … (#2749)

    * [blockchain] Create fresh big int, remove more dead code from static analysis

    * [measure] Remove IzZero/IsNil checks

commit 191f1d5
Author: Rongjian Lan <rongjian.lan@gmail.com>
Date:   Sun Apr 5 21:11:21 2020 -0700

    Final attempt: Don't div by 0; print out debug info (#2746)

    * Revert "Revert "fix earned-reward by writing the stats only once, remove from UpdateValdiatorVotingPower (#2737)" (#2742)"

    This reverts commit 832b01d.

    * Don't div by 0; print out debug info

commit 832b01d
Author: Edgar Aroutiounian <edgar.factorial@gmail.com>
Date:   Sun Apr 5 19:40:37 2020 -0700

    Revert "fix earned-reward by writing the stats only once, remove from UpdateValdiatorVotingPower (#2737)" (#2742)

    This reverts commit dc036e6.

commit dc036e6
Author: Ganesha Upadhyaya <ganeshrvce@gmail.com>
Date:   Sun Apr 5 17:18:36 2020 -0700

    fix earned-reward by writing the stats only once, remove from UpdateValdiatorVotingPower (#2737)

commit 66f26e8
Author: Rongjian Lan <rongjian.lan@gmail.com>
Date:   Sun Apr 5 17:06:50 2020 -0700

    do snapshot for validators at last block of epoch (#2736)

commit f2524a8
Author: Rongjian Lan <rongjian.lan@gmail.com>
Date:   Sun Apr 5 12:33:35 2020 -0700

    Make validator snapshot on new validator too (#2733)

commit 350b7a0
Author: Rongjian Lan <rongjian.lan@gmail.com>
Date:   Sat Apr 4 23:41:19 2020 -0700

    fix validator snapshot cache

commit 8f5f287
Author: Leo Chen <leo@harmony.one>
Date:   Sat Apr 4 19:09:38 2020 -0700

    [node.sh] use rclone to fast sync harmony_db_0 (#2709)

    Signed-off-by: Leo Chen <leo@harmony.one>

commit 05f2e20
Author: Rongjian Lan <rongjian.lan@gmail.com>
Date:   Sat Apr 4 19:00:28 2020 -0700

    make validator snapshot consistent with election (#2726)

    * make validator snapshot consistent with election

    * fix condition with only beacon chain

    * Fix epoch number

    * Fix stats update nil epoch issue

commit 24a17fe
Author: Edgar Aroutiounian <edgar.factorial@gmail.com>
Date:   Sat Apr 4 16:38:12 2020 -0700

    [state] ValidatorWrapper div zero panic fix -  (#2724)

    * [state] Error on div zero

    * [state] Do not pay out commit when commit is 0%

    * [state] Put whole commission in guarded block

    * [core] Reward cannot be zero

    * [state] return nil, not hard error

commit 1f83ebf
Author: Minh Doan <40258599+mikedoan@users.noreply.github.com>
Date:   Sat Apr 4 14:38:55 2020 -0700

    change explorer node storage folder (#2720)

commit 3aa08e9
Author: Edgar Aroutiounian <edgar.factorial@gmail.com>
Date:   Sat Apr 4 10:21:51 2020 -0700

    [rpc] Show both latest header of beacon chain and shard chain (#2714)

commit 1a2c23a
Author: Edgar Aroutiounian <edgar.factorial@gmail.com>
Date:   Fri Apr 3 17:49:24 2020 -0700

    [validator] Hide one field from JSON (#2705)
  • Loading branch information
fxfactorial authored Apr 6, 2020
1 parent 0c46e08 commit a876df6
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 135 deletions.
36 changes: 7 additions & 29 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ type BlockChain struct {
pendingCrossLinksMutex sync.RWMutex // pending crosslinks lock
pendingSlashingCandidatesMU sync.RWMutex // pending slashing candidates

checkpoint int // checkpoint counts towards the new checkpoint
currentBlock atomic.Value // Current head of the block chain
currentFastBlock atomic.Value // Current head of the fast-sync chain (may be above the block chain!)

Expand Down Expand Up @@ -1590,26 +1589,6 @@ func (bc *BlockChain) InsertHeaderChain(chain []*block.Header, checkFreq int) (i
return bc.hc.InsertHeaderChain(chain, whFunc, start)
}

// writeHeader writes a header into the local chain, given that its parent is
// already known. If the total difficulty of the newly inserted header becomes
// greater than the current known TD, the canonical chain is re-routed.
//
// Note: This method is not concurrent-safe with inserting blocks simultaneously
// into the chain, as side effects caused by reorganisations cannot be emulated
// without the real blocks. Hence, writing headers directly should only be done
// in two scenarios: pure-header mode of operation (light clients), or properly
// separated header/block phases (non-archive clients).
func (bc *BlockChain) writeHeader(header *block.Header) error {
bc.wg.Add(1)
defer bc.wg.Done()

bc.mu.Lock()
defer bc.mu.Unlock()

_, err := bc.hc.WriteHeader(header)
return err
}

// CurrentHeader retrieves the current head header of the canonical chain. The
// header is retrieved from the HeaderChain's internal cache.
func (bc *BlockChain) CurrentHeader() *block.Header {
Expand Down Expand Up @@ -2180,10 +2159,7 @@ func (bc *BlockChain) IsSpent(cxp *types.CXReceiptsProof) bool {
shardID := cxp.MerkleProof.ShardID
blockNum := cxp.MerkleProof.BlockNum.Uint64()
by, _ := rawdb.ReadCXReceiptsProofSpent(bc.db, shardID, blockNum)
if by == rawdb.SpentByte {
return true
}
return false
return by == rawdb.SpentByte
}

// ReadTxLookupEntry returns where the given transaction resides in the chain,
Expand Down Expand Up @@ -2349,7 +2325,7 @@ func (bc *BlockChain) UpdateValidatorVotingPower(
for i := range value {
earningWrapping[i] = staking.VoteWithCurrentEpochEarning{
Vote: value[i],
Earned: common.Big0,
Earned: big.NewInt(0),
}
}
stats.MetricsPerShard = earningWrapping
Expand Down Expand Up @@ -2714,7 +2690,7 @@ func (bc *BlockChain) addDelegationIndex(
// If there is an existing delegation, just return
validatorAddressBytes := validatorAddress.Bytes()
for _, delegation := range delegations {
if bytes.Compare(delegation.ValidatorAddress.Bytes(), validatorAddressBytes) == 0 {
if bytes.Equal(delegation.ValidatorAddress[:], validatorAddressBytes[:]) {
return delegations, nil
}
}
Expand All @@ -2726,7 +2702,9 @@ func (bc *BlockChain) addDelegationIndex(
return delegations, err
}
for i := range wrapper.Delegations {
if bytes.Compare(wrapper.Delegations[i].DelegatorAddress.Bytes(), delegatorAddress.Bytes()) == 0 {
if bytes.Equal(
wrapper.Delegations[i].DelegatorAddress[:], delegatorAddress[:],
) {
// TODO(audit): change the way of indexing if we allow delegation deletion.
delegations = append(delegations, staking.DelegationIndex{
validatorAddress,
Expand Down Expand Up @@ -2778,7 +2756,7 @@ func (bc *BlockChain) GetECDSAFromCoinbase(header *block.Header) (common.Address
}
for _, member := range committee.Slots {
// After staking the coinbase address will be the address of bls public key
if bytes.Compare(member.EcdsaAddress[:], coinbase[:]) == 0 {
if bytes.Equal(member.EcdsaAddress[:], coinbase[:]) {
return member.EcdsaAddress, nil
}

Expand Down
40 changes: 9 additions & 31 deletions core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,18 @@ import (
// BlockGen creates blocks for testing.
// See GenerateChain for a detailed explanation.
type BlockGen struct {
i int
parent *types.Block
chain []*types.Block
factory blockfactory.Factory
header *block.Header
statedb *state.DB

i int
parent *types.Block
chain []*types.Block
factory blockfactory.Factory
header *block.Header
statedb *state.DB
gasPool *GasPool
txs []*types.Transaction
stkTxs staking.StakingTransactions
receipts []*types.Receipt
uncles []*block.Header

config *params.ChainConfig
engine consensus_engine.Engine
config *params.ChainConfig
engine consensus_engine.Engine
}

// SetCoinbase sets the coinbase of the generated block.
Expand Down Expand Up @@ -248,27 +245,8 @@ func makeHeader(chain consensus_engine.ChainReader, parent *types.Block, state *
Header()
}

// makeHeaderChain creates a deterministic chain of headers rooted at parent.
func makeHeaderChain(parent *block.Header, n int, engine consensus_engine.Engine, db ethdb.Database, seed int) []*block.Header {
blocks := makeBlockChain(types.NewBlockWithHeader(parent), n, engine, db, seed)
headers := make([]*block.Header, len(blocks))
for i, block := range blocks {
headers[i] = block.Header()
}
return headers
}

// makeBlockChain creates a deterministic chain of blocks rooted at parent.
func makeBlockChain(parent *types.Block, n int, engine consensus_engine.Engine, db ethdb.Database, seed int) []*types.Block {
blocks, _ := GenerateChain(params.TestChainConfig, parent, engine, db, n, func(i int, b *BlockGen) {
b.SetCoinbase(common.Address{0: byte(seed), 19: byte(i)})
})
return blocks
}

type fakeChainReader struct {
config *params.ChainConfig
genesis *types.Block
config *params.ChainConfig
}

// Config returns the chain configuration.
Expand Down
42 changes: 0 additions & 42 deletions core/tx_cacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,9 @@
package core

import (
"runtime"

"github.com/ethereum/go-ethereum/core/types"
)

// senderCacher is a concurrent transaction sender recoverer anc cacher.
var senderCacher = newTxSenderCacher(runtime.NumCPU())

// txSenderCacherRequest is a request for recovering transaction senders with a
// specific signature scheme and caching it into the transactions themselves.
//
Expand Down Expand Up @@ -66,40 +61,3 @@ func (cacher *txSenderCacher) cache() {
}
}
}

// recover recovers the senders from a batch of transactions and caches them
// back into the same data structures. There is no validation being done, nor
// any reaction to invalid signatures. That is up to calling code later.
func (cacher *txSenderCacher) recover(signer types.Signer, txs []*types.Transaction) {
// If there's nothing to recover, abort
if len(txs) == 0 {
return
}
// Ensure we have meaningful task sizes and schedule the recoveries
tasks := cacher.threads
if len(txs) < tasks*4 {
tasks = (len(txs) + 3) / 4
}
for i := 0; i < tasks; i++ {
cacher.tasks <- &txSenderCacherRequest{
signer: signer,
txs: txs[i:],
inc: tasks,
}
}
}

// recoverFromBlocks recovers the senders from a batch of blocks and caches them
// back into the same data structures. There is no validation being done, nor
// any reaction to invalid signatures. That is up to calling code later.
func (cacher *txSenderCacher) recoverFromBlocks(signer types.Signer, blocks []*types.Block) {
count := 0
for _, block := range blocks {
count += len(block.Transactions())
}
txs := make([]*types.Transaction, 0, count)
for _, block := range blocks {
txs = append(txs, block.Transactions()...)
}
cacher.recover(signer, txs)
}
28 changes: 0 additions & 28 deletions core/tx_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,34 +176,6 @@ func validateTxPoolInternals(pool *TxPool) error {
return nil
}

// validateEvents checks that the correct number of transaction addition events
// were fired on the pool's event feed.
func validateEvents(events chan NewTxsEvent, count int) error {
var received []*types.Transaction

for len(received) < count {
select {
case ev := <-events:
received = append(received, ev.Txs...)
case <-time.After(time.Second):
return fmt.Errorf("event #%d not fired", len(received))
}
}
if len(received) > count {
return fmt.Errorf("more than %d events fired: %v", count, received[count:])
}
select {
case ev := <-events:
return fmt.Errorf("more than %d events fired: %v", count, ev.Txs)

case <-time.After(50 * time.Millisecond):
// This branch should be "default", but it's a data race between goroutines,
// reading the event channel and pushing into it, so better wait a bit ensuring
// really nothing gets injected.
}
return nil
}

func deriveSender(tx types.PoolTransaction) (common.Address, error) {
return types.PoolTransactionSender(types.HomesteadSigner{}, tx)
}
Expand Down
5 changes: 0 additions & 5 deletions staking/availability/measure.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,6 @@ func ComputeCurrentSigning(
}

s1, s2 := numeric.NewDecFromBigInt(signed), numeric.NewDecFromBigInt(toSign)
if s2.IsZero() || s2.IsNil() {
utils.Logger().Debug().Interface("s2", s2).
Msg("s2 is 0 or nil")
return computed
}
computed.Percentage = s1.Quo(s2)
computed.IsBelowThreshold = IsBelowSigningThreshold(computed.Percentage)
return computed
Expand Down

0 comments on commit a876df6

Please sign in to comment.