diff --git a/consensus/bor/bor.go b/consensus/bor/bor.go index 8b9cfc7fb7..e6d39fd7a3 100644 --- a/consensus/bor/bor.go +++ b/consensus/bor/bor.go @@ -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 } diff --git a/consensus/bor/rest.go b/consensus/bor/rest.go index 6e234c18ac..c46eb2dec5 100644 --- a/consensus/bor/rest.go +++ b/consensus/bor/rest.go @@ -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) } } diff --git a/consensus/bor/snapshot.go b/consensus/bor/snapshot.go index dc78a4ca1e..7928f0baea 100644 --- a/consensus/bor/snapshot.go +++ b/consensus/bor/snapshot.go @@ -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