Skip to content

Commit

Permalink
fixes after CR
Browse files Browse the repository at this point in the history
  • Loading branch information
JekaMas committed Oct 19, 2018
1 parent 3959f0c commit 5687ad6
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion client/core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ func (self *StateDB) RevertToSnapshot(revid int) {
})

if revertedIndex == -1 {
panic(fmt.Errorf("revision id %v cannot be reverted. found the revision at index %d. latest revision index %d",
log.Crit(fmt.Sprintf("revision id %v cannot be reverted. found the revision at index %d. latest revision index %d",
revid, idx, self.validRevisions[idx].id))
} else {
log.Warn("already reverted", "revisionID", revid)
Expand Down
7 changes: 4 additions & 3 deletions client/core/voting_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ func (table *votingTable) isDuplicate(voteAddressed types.AddressVote) error {
err := table.votes.Contains(voteAddressed)
if err != nil {
vote := voteAddressed.Vote()
log.Info(fmt.Sprintf("a duplicate vote in voting table %v; blockHash %v; voteHash %v; from validator %v. Error: %s",
table.voteType, vote.BlockHash(), vote.Hash(), voteAddressed.Address(), vote.String()))
log.Debug(fmt.Sprintf("a duplicate vote in voting table %v; blockHash %v; voteHash %v; from validator %v. Error: %s",
table.voteType, vote.BlockHash().String(), vote.Hash().String(), voteAddressed.Address().String(), vote.String()))
return err
}
return nil
}
Expand All @@ -78,7 +79,7 @@ func (table *votingTable) hasQuorum() bool {
isQuorum := table.quorum(int64(leaderBlockVotes), int64(table.voters.Len()))

log.Debug("voting. hasQuorum", "leaderVotes", leaderBlockVotes, "votes", table.votes.Len(),
"voters", table.voters.Len(), "isQuorum", isQuorum, "leader", table.Leader())
"voters", table.voters.Len(), "isQuorum", isQuorum, "leader", table.Leader().String())

return isQuorum
}
Expand Down
2 changes: 1 addition & 1 deletion client/knode/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {

p.MarkBlockFragment(request.Data.Proof)
if err := pm.validator.AddBlockFragment(request.BlockNumber, request.Hash, request.Round, request.Data); err != nil {
log.Error("error while adding a new block fragment", "err", err, "round", request.Round, "block", request.BlockNumber, "fragment", request.Data)
log.Debug("error while adding a new block fragment", "err", err, "round", request.Round, "block", request.BlockNumber, "fragment", request.Data)
// ignore
break
}
Expand Down
2 changes: 1 addition & 1 deletion client/knode/validator/poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (p *poster) EventPost(event interface{}) {
log.Warn("can't post an event", "err", err, "event", event)
}
default:
log.Error("unknown validator event", "event", event)
log.Debug("unknown validator event", "event", event)
}
}
}()
Expand Down
8 changes: 4 additions & 4 deletions client/knode/validator/states.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func (val *validator) notLoggedInState() stateFn {
try := 0
err = val.join()
for err != nil {
log.Error("Failed to make deposit", "try", try, "err", err)
time.Sleep(3 * time.Second)

isValidator, err = val.consensus.IsValidator(val.walletAccount.Account().Address)
Expand All @@ -57,14 +58,13 @@ func (val *validator) notLoggedInState() stateFn {
break
}

if err = val.join(); err != nil {
log.Error("Failed to make deposit", "try", try, "err", err)
}
err = val.join()

if try >= 10 {
log.Error("Failed to make deposit. Stopping validation", "try", try)
return nil
}
try++
}
log.Warn("started as a validator")
}
Expand Down Expand Up @@ -160,7 +160,7 @@ func (val *validator) waitForProposal() {
select {
case block := <-val.blockCh:
if val.blockNumber.Cmp(block.Number()) != 0 {
log.Error(fmt.Sprintf("expected proposed block number %v, got %v",
log.Warn(fmt.Sprintf("expected proposed block number %v, got %v",
val.blockNumber.Int64(), block.Number().Int64()))
}

Expand Down
23 changes: 13 additions & 10 deletions client/knode/validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func (val *validator) init() error {

val.checkUpdateValidators(true)

val.blockCh = make(chan *types.Block)
val.blockCh = make(chan *types.Block, 1)
val.majority = val.eventMux.Subscribe(core.NewMajorityEvent{})

if err := val.makeCurrent(parent); err != nil {
Expand Down Expand Up @@ -353,7 +353,7 @@ func (val *validator) AddProposal(proposal *types.Proposal) error {
}

if blockFragments.HasAll() {
log.Info("addProposal has all fragments and assembling a block")
log.Debug("addProposal has all fragments and assembling a block")
return val.assembleBlock(proposal.Round(), proposal.BlockNumber(), proposal.Hash())
}

Expand Down Expand Up @@ -384,7 +384,7 @@ func (val *validator) AddVote(vote *types.Vote) error {
}

if err := val.votingSystem.Add(addressVote); err != nil {
log.Error("cannot add the vote", "err", err)
log.Debug("cannot add the vote", "err", err)
}

return nil
Expand Down Expand Up @@ -735,7 +735,7 @@ func (val *validator) vote(vote *types.Vote) {

err = val.votingSystem.Add(addressVote)
if err != nil {
log.Error("Failed to add own vote to voting table",
log.Debug("Failed to add own vote to voting table",
"err", err, "blockHash", addressVote.Vote().BlockHash(), "hash", addressVote.Vote().Hash())
}
}
Expand All @@ -755,7 +755,7 @@ func (val *validator) AddBlockFragment(blockNumber *big.Int, blockHash common.Ha
}

if canAssemble {
log.Info("addBlockFragment has all fragments and assembling a block")
log.Debug("addBlockFragment has all fragments and assembling a block")
return val.assembleBlock(round, blockNumber, blockHash)
}

Expand Down Expand Up @@ -786,7 +786,7 @@ func (val *validator) addFragment(fragment *types.BlockFragment, blockHash commo
// if val.blockFragments is set, proposal block metadata was received
for _, blockFragment := range blockFragmentsList {
if err := blockFragments.Add(blockFragment); err != nil {
log.Error("failed to add a new block fragment", "err", err.Error())
log.Debug("failed to add a new block fragment", "err", err.Error())
}
}

Expand All @@ -813,7 +813,7 @@ func (val *validator) assembleBlock(round uint64, blockNumber *big.Int, blockHas
block, err := blockFragments.Assemble()
if err != nil {
err = errors.New("Failed to assemble the block: " + err.Error())
log.Error("error while adding a new block fragment", "err", err,
log.Warn("error while adding a new block fragment", "err", err,
"round", round, "block", blockNumber)
return err
}
Expand All @@ -824,6 +824,10 @@ func (val *validator) assembleBlock(round uint64, blockNumber *big.Int, blockHas
}

parent := val.chain.GetBlock(block.ParentHash(), block.NumberU64()-1)
if parent == nil {
return fmt.Errorf("wrong block received. hash %v, number %v, parentHash %v",
block.Hash().String(), block.Number().Int64(), block.ParentHash().String())
}

// Process block using the parent state as reference point.
receipts, _, usedGas, err := val.chain.Processor().Process(block, val.state, val.vmConfig)
Expand All @@ -850,7 +854,6 @@ func (val *validator) assembleBlock(round uint64, blockNumber *big.Int, blockHas

val.block = block

//fixme goroutine leak
go func() { val.blockCh <- block }()

return nil
Expand All @@ -867,7 +870,7 @@ func (val *validator) validateProposalBlock(block *types.Block, round uint64, bl

err := <-results
if err != nil {
log.Error("error while verifying a block headers",
log.Debug("error while verifying a block headers",
"err", err, "round", round, "block", blockNumber, "block",
block, "headers", headers, "seals", seals)
return err
Expand All @@ -876,7 +879,7 @@ func (val *validator) validateProposalBlock(block *types.Block, round uint64, bl
err = val.chain.Validator().ValidateBody(block)
if err != nil {
err = errors.New("Failed to validate thr block body: " + err.Error())
log.Error("error while validating a block body",
log.Debug("error while validating a block body",
"err", err, "round", round, "block", blockNumber, "block", block)

return err
Expand Down
2 changes: 1 addition & 1 deletion e2e/impl/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func (ctx *Context) triggerGenesisValidation() error {
return err
}

return common.WaitFor("validation starts", 2*time.Second, 20*time.Second, func() error {
return common.WaitFor("validation starts", 2*time.Second, 40*time.Second, func() error {
res, err := ctx.nodeRunner.Exec(ctx.genesisValidatorNodeID, cluster.KcoinExecCommand("eth.blockNumber"))
if err != nil {
return err
Expand Down

0 comments on commit 5687ad6

Please sign in to comment.