remove log

This commit is contained in:
Jaynti Kanani 2019-09-26 12:49:35 +05:30
parent 25a8cb4766
commit 6cc7e88e94
No known key found for this signature in database
GPG key ID: 4396982C976BAE5E
4 changed files with 9 additions and 49 deletions

View file

@ -3,7 +3,6 @@ package bor
import ( import (
"bytes" "bytes"
"context" "context"
"encoding/hex"
"errors" "errors"
"fmt" "fmt"
"io" "io"
@ -41,7 +40,7 @@ const (
inmemorySnapshots = 128 // Number of recent vote snapshots to keep in memory inmemorySnapshots = 128 // Number of recent vote snapshots to keep in memory
inmemorySignatures = 4096 // Number of recent block signatures to keep in memory inmemorySignatures = 4096 // Number of recent block signatures to keep in memory
wiggleTime = 1000 * time.Millisecond // Random delay (per signer) to allow concurrent signers wiggleTime = 5000 * time.Millisecond // Random delay (per signer) to allow concurrent signers
) )
// Bor protocol constants. // Bor protocol constants.
@ -203,7 +202,6 @@ func CalcProducerDelay(snap *Snapshot, signer common.Address, period uint64, epo
// if block is epoch start block, proposer will be inturn signer // if block is epoch start block, proposer will be inturn signer
if (snap.Number+1)%epoch == 0 { if (snap.Number+1)%epoch == 0 {
fmt.Println("==>", "producerDelay", producerDelay, "(snap.Number+1)%epoch", (snap.Number+1)%epoch)
return producerDelay return producerDelay
// if block is not epoch block, last block signer will be inturn // if block is not epoch block, last block signer will be inturn
@ -405,24 +403,20 @@ func (c *Bor) verifyCascadingFields(chain consensus.ChainReader, header *types.H
extraSuffix := len(header.Extra) - extraSeal extraSuffix := len(header.Extra) - extraSeal
fmt.Println("validatorsBytes ==> verify seal ==> ", hex.EncodeToString(validatorsBytes)) // fmt.Println("validatorsBytes ==> verify seal ==> ", hex.EncodeToString(validatorsBytes))
fmt.Println("header.Extra ==> verify seal ==> ", hex.EncodeToString(header.Extra[extraVanity:extraSuffix])) // fmt.Println("header.Extra ==> verify seal ==> ", hex.EncodeToString(header.Extra[extraVanity:extraSuffix]))
// if !bytes.Equal(header.Extra[extraVanity:extraSuffix], validatorsBytes) { if !bytes.Equal(header.Extra[extraVanity:extraSuffix], validatorsBytes) {
// return errMismatchingSprintValidators // return errMismatchingSprintValidators
// } }
} }
fmt.Println("verifySeal header", "number", header.Number.String(), "extra", hex.EncodeToString(header.Extra))
// All basic checks passed, verify the seal and return // All basic checks passed, verify the seal and return
return c.verifySeal(chain, header, parents) return c.verifySeal(chain, header, parents)
} }
// snapshot retrieves the authorization snapshot at a given point in time. // snapshot retrieves the authorization snapshot at a given point in time.
func (c *Bor) snapshot(chain consensus.ChainReader, number uint64, hash common.Hash, parents []*types.Header) (*Snapshot, error) { func (c *Bor) snapshot(chain consensus.ChainReader, number uint64, hash common.Hash, parents []*types.Header) (*Snapshot, error) {
fmt.Println("Start bor.snapshot", number)
defer func(x uint64) { fmt.Println("End bor.snapshot", x) }(number)
// Search for a snapshot in memory or on disk for checkpoints // Search for a snapshot in memory or on disk for checkpoints
var ( var (
headers []*types.Header headers []*types.Header
@ -438,7 +432,6 @@ func (c *Bor) snapshot(chain consensus.ChainReader, number uint64, hash common.H
// If an on-disk checkpoint snapshot can be found, use that // If an on-disk checkpoint snapshot can be found, use that
if number%checkpointInterval == 0 { if number%checkpointInterval == 0 {
fmt.Println("loading snapshot for number", number, "checkpointInterval", checkpointInterval)
if s, err := loadSnapshot(c.config, c.signatures, c.db, hash, c.ethAPI); err == nil { if s, err := loadSnapshot(c.config, c.signatures, c.db, hash, c.ethAPI); err == nil {
log.Trace("Loaded snapshot from disk", "number", number, "hash", hash) log.Trace("Loaded snapshot from disk", "number", number, "hash", hash)
snap = s snap = s
@ -587,21 +580,16 @@ func (c *Bor) verifySeal(chain consensus.ChainReader, header *types.Header, pare
if !c.fakeDiff { if !c.fakeDiff {
difficulty := snap.inturn(header.Number.Uint64(), signer, c.config.Sprint) difficulty := snap.inturn(header.Number.Uint64(), signer, c.config.Sprint)
if header.Difficulty.Uint64() != difficulty { if header.Difficulty.Uint64() != difficulty {
fmt.Println("difficulty ==>", difficulty, "header.Difficulty", header.Difficulty, "header.Number", header.Number, "signer", signer.Hex(), "sprint", c.config.Sprint, "validatorSet", snap.ValidatorSet)
return errWrongDifficulty return errWrongDifficulty
} }
} }
fmt.Println("==> New block", "number", header.Number, "hash", header.Hash().Hex(), "signer", signer.Hex(), "proposer", proposer.Hex())
return nil return nil
} }
// Prepare implements consensus.Engine, preparing all the consensus fields of the // Prepare implements consensus.Engine, preparing all the consensus fields of the
// header for running the transactions on top. // header for running the transactions on top.
func (c *Bor) Prepare(chain consensus.ChainReader, header *types.Header) error { func (c *Bor) Prepare(chain consensus.ChainReader, header *types.Header) error {
fmt.Println("Start bor.Prepare", header.Number.Uint64())
defer func(d uint64) { fmt.Println("End bor.Prepare", d) }(header.Number.Uint64())
// If the block isn't a checkpoint, cast a random vote (good enough for now) // If the block isn't a checkpoint, cast a random vote (good enough for now)
header.Coinbase = common.Address{} header.Coinbase = common.Address{}
header.Nonce = types.BlockNonce{} header.Nonce = types.BlockNonce{}
@ -652,7 +640,6 @@ func (c *Bor) Prepare(chain consensus.ChainReader, header *types.Header) error {
if header.Time < uint64(time.Now().Unix()) { if header.Time < uint64(time.Now().Unix()) {
header.Time = uint64(time.Now().Unix()) header.Time = uint64(time.Now().Unix())
} }
fmt.Println("parent.Time", parent.Time, "header.Time", header.Time, "number", header.Number, "extra", hex.EncodeToString(header.Extra))
return nil return nil
} }
@ -715,7 +702,6 @@ func (c *Bor) Seal(chain consensus.ChainReader, block *types.Block, results chan
return errUnauthorizedSigner return errUnauthorizedSigner
} }
fmt.Println("Validators", number, snap.ValidatorSet)
validators := snap.ValidatorSet.Validators validators := snap.ValidatorSet.Validators
// proposer will be the last signer if block is not epoch block // proposer will be the last signer if block is not epoch block
proposer := snap.ValidatorSet.GetProposer().Address proposer := snap.ValidatorSet.GetProposer().Address
@ -723,7 +709,6 @@ func (c *Bor) Seal(chain consensus.ChainReader, block *types.Block, results chan
// proposer = snap.Recents[number-1] // proposer = snap.Recents[number-1]
} }
fmt.Println("Sealing block", number, "validatorset", snap.ValidatorSet)
proposerIndex, _ := snap.ValidatorSet.GetByAddress(proposer) proposerIndex, _ := snap.ValidatorSet.GetByAddress(proposer)
signerIndex, _ := snap.ValidatorSet.GetByAddress(signer) signerIndex, _ := snap.ValidatorSet.GetByAddress(signer)
limit := len(validators) - (len(validators)/2 + 1) limit := len(validators) - (len(validators)/2 + 1)
@ -733,7 +718,7 @@ func (c *Bor) Seal(chain consensus.ChainReader, block *types.Block, results chan
if tempIndex < proposerIndex { if tempIndex < proposerIndex {
tempIndex = tempIndex + len(validators) tempIndex = tempIndex + len(validators)
} }
fmt.Println("Block temp index", "number", number, "tempIndex", tempIndex, "proposerIndex", proposerIndex)
if limit > 0 && tempIndex-proposerIndex > limit { if limit > 0 && tempIndex-proposerIndex > limit {
log.Info("Signed recently, must wait for others") log.Info("Signed recently, must wait for others")
return nil return nil
@ -745,7 +730,7 @@ func (c *Bor) Seal(chain consensus.ChainReader, block *types.Block, results chan
delay += wiggle delay += wiggle
fmt.Println("Out-of-turn signing requested", "wiggle", common.PrettyDuration(wiggle)) fmt.Println("Out-of-turn signing requested", "wiggle", common.PrettyDuration(wiggle))
fmt.Println("--> Sealing block with", "number", number, "delay", delay, "headerDifficulty", header.Difficulty, "signer", signer.Hex(), "proposer", proposer.Hex()) fmt.Println("Sealing block with", "number", number, "delay", delay, "headerDifficulty", header.Difficulty, "signer", signer.Hex(), "proposer", proposer.Hex())
// Sign all the things! // Sign all the things!
sighash, err := signFn(accounts.Account{Address: signer}, accounts.MimetypeBor, BorRLP(header)) sighash, err := signFn(accounts.Account{Address: signer}, accounts.MimetypeBor, BorRLP(header))
@ -812,9 +797,6 @@ func (c *Bor) GetCurrentValidators(snapshotNumber uint64, blockNumber uint64) ([
// GetValidators get current validators // GetValidators get current validators
func GetValidators(snapshotNumber uint64, blockNumber uint64, sprint uint64, validatorContract string, ethAPI *ethapi.PublicBlockChainAPI) ([]*Validator, error) { func GetValidators(snapshotNumber uint64, blockNumber uint64, sprint uint64, validatorContract string, ethAPI *ethapi.PublicBlockChainAPI) ([]*Validator, error) {
fmt.Println("Start bor.GetValdiators", snapshotNumber)
defer func(x uint64) { fmt.Println("End bor.GetValdiators", x) }(snapshotNumber)
// block // block
blockNr := rpc.BlockNumber(snapshotNumber) blockNr := rpc.BlockNumber(snapshotNumber)
@ -857,7 +839,6 @@ func GetValidators(snapshotNumber uint64, blockNumber uint64, sprint uint64, val
} }
if err := validatorSetABI.Unpack(out, method, result); err != nil { if err := validatorSetABI.Unpack(out, method, result); err != nil {
fmt.Println("err", err)
return nil, err return nil, err
} }
@ -869,8 +850,6 @@ func GetValidators(snapshotNumber uint64, blockNumber uint64, sprint uint64, val
} }
} }
fmt.Println(method)
fmt.Println(" === ", valz)
return valz, nil return valz, nil
} }

View file

@ -80,7 +80,6 @@ func newSnapshot(config *params.BorConfig, sigcache *lru.ARCCache, number uint64
Recents: make(map[uint64]common.Address), Recents: make(map[uint64]common.Address),
// Tally: make(map[common.Address]Tally), // Tally: make(map[common.Address]Tally),
} }
fmt.Println("New validator set", "number", number, "proposer", snap.ValidatorSet.Proposer.Address.Hex())
return snap return snap
} }
@ -209,26 +208,15 @@ func (s *Snapshot) apply(headers []*types.Header) (*Snapshot, error) {
return nil, err return nil, err
} }
// fmt.Println("In snapshot 1 ==>", "number", header.Number.String())
// change validator set and change proposer // change validator set and change proposer
if number > 0 && (number+1)%s.config.Sprint == 0 { if number > 0 && (number+1)%s.config.Sprint == 0 {
fmt.Println("before snap.ValidatorSet changed", snap.ValidatorSet, snap.ValidatorSet.TotalVotingPower())
// fmt.Println("In snapshot 2 ==>", "number", header.Number.String(), "extra", hex.EncodeToString(header.Extra))
validatorBytes := header.Extra[extraVanity : len(header.Extra)-extraSeal] validatorBytes := header.Extra[extraVanity : len(header.Extra)-extraSeal]
newVals, err := ParseValidators(validatorBytes)
if err != nil {
fmt.Println("err ==>", err)
}
fmt.Println(" newVals ==> ", newVals)
// newVals, _ := GetValidators(number, number+1, s.config.Sprint, s.config.ValidatorContract, snap.ethAPI) // newVals, _ := GetValidators(number, number+1, s.config.Sprint, s.config.ValidatorContract, snap.ethAPI)
newVals, _ := ParseValidators(validatorBytes)
v := getUpdatedValidatorSet(snap.ValidatorSet.Copy(), newVals) v := getUpdatedValidatorSet(snap.ValidatorSet.Copy(), newVals)
fmt.Println("middle snap.ValidatorSet changed", v)
v.IncrementProposerPriority(1) v.IncrementProposerPriority(1)
snap.ValidatorSet = v snap.ValidatorSet = v
fmt.Println("after snap.ValidatorSet changed", snap.ValidatorSet)
} }
// check if signer is in validator set // check if signer is in validator set
@ -270,8 +258,6 @@ func (s *Snapshot) apply(headers []*types.Header) (*Snapshot, error) {
snap.Number += uint64(len(headers)) snap.Number += uint64(len(headers))
snap.Hash = headers[len(headers)-1].Hash() snap.Hash = headers[len(headers)-1].Hash()
fmt.Println("ValidatorsSet => ", snap.Number, snap.ValidatorSet)
return snap, nil return snap, nil
} }

View file

@ -2,7 +2,6 @@ package bor
import ( import (
"bytes" "bytes"
"encoding/hex"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
@ -93,11 +92,8 @@ func (v *Validator) Bytes() []byte {
// HeaderBytes return header bytes // HeaderBytes return header bytes
func (v *Validator) HeaderBytes() []byte { func (v *Validator) HeaderBytes() []byte {
result := make([]byte, 40) result := make([]byte, 40)
fmt.Println("validator.Address.Bytes()", hex.EncodeToString(v.Address.Bytes()))
fmt.Println("getPowerBytes(big.NewInt(0).SetInt64(validator.VotingPower))", hex.EncodeToString(v.PowerBytes()))
copy(result[:20], v.Address.Bytes()) copy(result[:20], v.Address.Bytes())
copy(result[20:], v.PowerBytes()) copy(result[20:], v.PowerBytes())
fmt.Println("HeaderBytes result ==>", hex.EncodeToString(result))
return result return result
} }

View file

@ -277,7 +277,6 @@ func (vals *ValidatorSet) updateTotalVotingPower() {
// It recomputes the total voting power if required. // It recomputes the total voting power if required.
func (vals *ValidatorSet) TotalVotingPower() int64 { func (vals *ValidatorSet) TotalVotingPower() int64 {
if vals.totalVotingPower == 0 { if vals.totalVotingPower == 0 {
fmt.Println(" === == == == total voting power : zero")
vals.updateTotalVotingPower() vals.updateTotalVotingPower()
} }
return vals.totalVotingPower return vals.totalVotingPower