Merge pull request #10 from maticnetwork/log_updates

log usage standardised
This commit is contained in:
Vaibhav Chellani 2019-12-04 18:44:46 +05:30 committed by GitHub
commit b6f6ce9630
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 17 deletions

View file

@ -667,13 +667,13 @@ func (c *Bor) Finalize(chain consensus.ChainReader, header *types.Header, state
// check and commit span
if err := c.checkAndCommitSpan(state, header, cx); err != nil {
fmt.Println("Error while committing span", err)
log.Error("Error while committing span", "error", err)
return
}
// commit statees
if err := c.CommitStates(state, header, cx); err != nil {
fmt.Println("Error while committing states", err)
log.Error("Error while committing states", "error", err)
return
}
}
@ -693,13 +693,13 @@ func (c *Bor) FinalizeAndAssemble(chain consensus.ChainReader, header *types.Hea
// check and commit span
err := c.checkAndCommitSpan(state, header, cx)
if err != nil {
fmt.Println("Error while committing span", err)
log.Error("Error while committing span", "error", err)
return nil, err
}
// commit statees
if err := c.CommitStates(state, header, cx); err != nil {
fmt.Println("Error while committing states", err)
log.Error("Error while committing states", "error", err)
// return nil, err
}
}
@ -779,8 +779,8 @@ func (c *Bor) Seal(chain consensus.ChainReader, block *types.Block, results chan
wiggle := time.Duration(2*c.config.Period) * time.Second * time.Duration(tempIndex-proposerIndex)
delay += 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())
log.Info("Out-of-turn signing requested", "wiggle", common.PrettyDuration(wiggle))
log.Info("Sealing block with", "number", number, "delay", delay, "headerDifficulty", header.Difficulty, "signer", signer.Hex(), "proposer", proposer.Hex())
// Sign all the things!
sighash, err := signFn(accounts.Account{Address: signer}, accounts.MimetypeBor, BorRLP(header))
@ -848,7 +848,7 @@ func (c *Bor) isSpanPending(snapshotNumber uint64) (bool, error) {
// get packed data
data, err := c.validatorSetABI.Pack(method)
if err != nil {
fmt.Println("Unable to pack tx for spanProposalPending", "error", err)
log.Error("Unable to pack tx for spanProposalPending", "error", err)
return false, err
}
@ -886,7 +886,7 @@ func (c *Bor) GetCurrentSpan(snapshotNumber uint64) (*Span, error) {
data, err := c.validatorSetABI.Pack(method)
if err != nil {
fmt.Println("Unable to pack tx for getCurrentSpan", "error", err)
log.Error("Unable to pack tx for getCurrentSpan", "error", err)
return nil, err
}
@ -936,7 +936,7 @@ func (c *Bor) GetCurrentValidators(snapshotNumber uint64, blockNumber uint64) ([
data, err := c.validatorSetABI.Pack(method, big.NewInt(0).SetUint64(blockNumber))
if err != nil {
fmt.Println("Unable to pack tx for getValidator", "error", err)
log.Error("Unable to pack tx for getValidator", "error", err)
return nil, err
}
@ -1070,8 +1070,7 @@ func (c *Bor) commitSpan(
// method
method := "commitSpan"
fmt.Println(
log.Info("✅ Committing new span",
"id", heimdallSpan.ID,
"startBlock", heimdallSpan.StartBlock,
"endBlock", heimdallSpan.EndBlock,
@ -1088,7 +1087,7 @@ func (c *Bor) commitSpan(
producerBytes,
)
if err != nil {
fmt.Println("Unable to pack tx for commitSpan", "error", err)
log.Error("Unable to pack tx for commitSpan", "error", err)
return err
}
@ -1109,7 +1108,7 @@ func (c *Bor) GetPendingStateProposals(snapshotNumber uint64) ([]*big.Int, error
data, err := c.stateReceiverABI.Pack(method)
if err != nil {
fmt.Println("Unable to pack tx for getPendingStates", "error", err)
log.Error("Unable to pack tx for getPendingStates", "error", err)
return nil, err
}
@ -1150,7 +1149,7 @@ func (c *Bor) CommitStates(
// state ids
if len(stateIds) > 0 {
fmt.Println("Found new proposed states", len(stateIds))
log.Debug("Found new proposed states", "numberOfStates", len(stateIds))
}
method := "commitState"
@ -1168,6 +1167,12 @@ func (c *Bor) CommitStates(
if err := json.Unmarshal(response.Result, &eventRecord); err != nil {
return err
}
log.Info("→ committing new state",
"id", eventRecord.ID,
"contract", eventRecord.Contract,
"data", hex.EncodeToString(eventRecord.Data),
"txHash", eventRecord.TxHash,
)
recordBytes, err := rlp.EncodeToBytes(eventRecord)
if err != nil {
@ -1177,7 +1182,7 @@ func (c *Bor) CommitStates(
// get packed data for commit state
data, err := c.stateReceiverABI.Pack(method, recordBytes)
if err != nil {
fmt.Println("Unable to pack tx for commitState", "error", err)
log.Error("Unable to pack tx for commitState", "error", err)
return err
}

View file

@ -8,6 +8,8 @@ import (
"net/url"
"path"
"time"
"github.com/maticnetwork/bor/log"
)
// ResponseWithHeight defines a response object type that wraps an original
@ -63,7 +65,7 @@ func FetchFromHeimdallWithRetry(client http.Client, urlString string, paths ...s
if err == nil && res != nil {
return res, nil
}
fmt.Println("Retrying again in 5 seconds", u.String())
log.Info("Retrying again in 5 seconds", u.String())
time.Sleep(5 * time.Second)
}
}

View file

@ -19,13 +19,13 @@ package bor
import (
"bytes"
"encoding/json"
"fmt"
lru "github.com/hashicorp/golang-lru"
"github.com/maticnetwork/bor/common"
"github.com/maticnetwork/bor/core/types"
"github.com/maticnetwork/bor/ethdb"
"github.com/maticnetwork/bor/internal/ethapi"
"github.com/maticnetwork/bor/log"
"github.com/maticnetwork/bor/params"
)
@ -150,6 +150,23 @@ func (s *Snapshot) apply(headers []*types.Header) (*Snapshot, error) {
return nil, err
}
<<<<<<< HEAD
// change validator set and change proposer
if number > 0 && (number+1)%s.config.Sprint == 0 {
validatorBytes := header.Extra[extraVanity : len(header.Extra)-extraSeal]
// get validators from headers and use that for new validator set
newVals, _ := ParseValidators(validatorBytes)
v := getUpdatedValidatorSet(snap.ValidatorSet.Copy(), newVals)
v.IncrementProposerPriority(1)
snap.ValidatorSet = v
// log new validator set
log.Info("Current validator set", "number", snap.Number, "validatorSet", snap.ValidatorSet)
}
=======
>>>>>>> origin/mat-494
// check if signer is in validator set
if !snap.ValidatorSet.HasAddress(signer.Bytes()) {
return nil, errUnauthorizedSigner