From 2ea69833dd2e5300dccdde5bd5c60a2d8e59d20c Mon Sep 17 00:00:00 2001 From: atvanguard <93arpit@gmail.com> Date: Mon, 16 Mar 2020 20:52:09 +0530 Subject: [PATCH] Cleanup debug statements --- consensus/bor/api.go | 4 ---- consensus/bor/bor.go | 29 +++++++++++++---------------- crypto/secp256k1/secp256.go | 1 - internal/ethapi/api.go | 1 - les/api_backend.go | 3 --- 5 files changed, 13 insertions(+), 25 deletions(-) diff --git a/consensus/bor/api.go b/consensus/bor/api.go index d1d151c216..98f7c46b6e 100644 --- a/consensus/bor/api.go +++ b/consensus/bor/api.go @@ -30,10 +30,6 @@ type API struct { bor *Bor } -func NewBorApi(chain consensus.ChainReader, bor *Bor) API { - return API{chain: chain, bor: bor} -} - // GetSnapshot retrieves the state snapshot at a given block. func (api *API) GetSnapshot(number *rpc.BlockNumber) (*Snapshot, error) { // Retrieve the requested block number (or current if none requested) diff --git a/consensus/bor/bor.go b/consensus/bor/bor.go index 590d19c9d4..127a396854 100644 --- a/consensus/bor/bor.go +++ b/consensus/bor/bor.go @@ -11,7 +11,6 @@ import ( "math" "math/big" - // "net/http" "sort" "strconv" "strings" @@ -327,6 +326,7 @@ func (c *Bor) verifyHeader(chain consensus.ChainReader, header *types.Header, pa return errUnknownBlock } number := header.Number.Uint64() + // Don't waste time checking blocks from the future if header.Time > uint64(time.Now().Unix()) { return consensus.ErrFutureBlock @@ -338,8 +338,10 @@ func (c *Bor) verifyHeader(chain consensus.ChainReader, header *types.Header, pa if len(header.Extra) < extraVanity+extraSeal { return errMissingSignature } + // check extr adata isSprintEnd := (number+1)%c.config.Sprint == 0 + // Ensure that the extra-data contains a signer list on checkpoint, but none otherwise signersBytes := len(header.Extra) - extraVanity - extraSeal if !isSprintEnd && signersBytes != 0 { @@ -425,7 +427,6 @@ func (c *Bor) verifyCascadingFields(chain consensus.ChainReader, header *types.H } // All basic checks passed, verify the seal and return - // return nil return c.verifySeal(chain, header, parents) } @@ -562,6 +563,7 @@ func (c *Bor) verifySeal(chain consensus.ChainReader, header *types.Header, pare if err != nil { return err } + if !snap.ValidatorSet.HasAddress(signer.Bytes()) { return errUnauthorizedSigner } @@ -662,13 +664,10 @@ func (c *Bor) Finalize(chain consensus.ChainReader, header *types.Header, state // commit span headerNumber := header.Number.Uint64() - // @todo check if this is required - if /* headerNumber > 0 && */ - headerNumber%c.config.Sprint == 0 { + if headerNumber%c.config.Sprint == 0 { cx := chainContext{Chain: chain, Bor: c} // 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 } @@ -991,22 +990,16 @@ func (c *Bor) checkAndCommitSpan( pending := false var span *Span = nil errors := make(chan error) - // var wg sync.WaitGroup - // wg.Add(1) go func() { var err error pending, err = c.isSpanPending(headerNumber - 1) - // pending, err = c.isSpanPending(headerNumber) errors <- err - // wg.Done() }() - // wg.Add(1) go func() { var err error span, err = c.GetCurrentSpan(headerNumber - 1) errors <- err - // wg.Done() }() var err error @@ -1061,6 +1054,7 @@ func (c *Bor) fetchAndCommitSpan( if err := json.Unmarshal(response.Result, &heimdallSpan); err != nil { return err } + // check if chain id matches with heimdall span if heimdallSpan.ChainID != c.chainConfig.ChainID.String() { return fmt.Errorf( @@ -1069,6 +1063,7 @@ func (c *Bor) fetchAndCommitSpan( c.chainConfig.ChainID, ) } + // get validators bytes var validators []MinimalVal for _, val := range heimdallSpan.ValidatorSet.Validators { @@ -1078,6 +1073,7 @@ func (c *Bor) fetchAndCommitSpan( if err != nil { return err } + // get producers bytes var producers []MinimalVal for _, val := range heimdallSpan.SelectedProducers { @@ -1097,6 +1093,7 @@ func (c *Bor) fetchAndCommitSpan( "validatorBytes", hex.EncodeToString(validatorBytes), "producerBytes", hex.EncodeToString(producerBytes), ) + // get packed data data, err := c.validatorSetABI.Pack(method, big.NewInt(0).SetUint64(heimdallSpan.ID), @@ -1109,8 +1106,10 @@ func (c *Bor) fetchAndCommitSpan( log.Error("Unable to pack tx for commitSpan", "error", err) return err } + // get system message msg := getSystemMessage(common.HexToAddress(c.config.ValidatorContract), data) + // apply message return applyMessage(msg, state, header, c.chainConfig, chain) } @@ -1235,6 +1234,7 @@ func (c *Bor) IsValidatorAction(chain consensus.ChainReader, from common.Address snap, err := c.snapshot(chain, header.Number.Uint64(), header.Hash(), nil) if err != nil { log.Error("Failed fetching snapshot", err) + return false } isValidator := false @@ -1276,10 +1276,6 @@ type chainContext struct { Bor consensus.Engine } -// func NewChainContext(chain consensus.ChainReader, bor consensus.Engine) (chainContext) { -// return {Chain: chain, Bor: bor} -// } - func (c chainContext) Engine() consensus.Engine { return c.Bor } @@ -1341,6 +1337,7 @@ func applyMessage( if err != nil { state.Finalise(true) } + return nil } diff --git a/crypto/secp256k1/secp256.go b/crypto/secp256k1/secp256.go index 191e158f05..35d0eef34a 100644 --- a/crypto/secp256k1/secp256.go +++ b/crypto/secp256k1/secp256.go @@ -59,7 +59,6 @@ func Sign(msg []byte, seckey []byte) ([]byte, error) { if len(msg) != 32 { return nil, ErrInvalidMsgLen } - if len(seckey) != 32 { return nil, ErrInvalidKey } diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 7b56ba612e..2a939ed2c4 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -730,7 +730,6 @@ func DoCall(ctx context.Context, b Backend, args CallArgs, blockNr rpc.BlockNumb defer func(start time.Time) { log.Debug("Executing EVM call finished", "runtime", time.Since(start)) }(time.Now()) state, header, err := b.StateAndHeaderByNumber(ctx, blockNr) - // fmt.Println("statedb.IntermediateRoot in DoCall", state.IntermediateRoot(false).Hex()) if state == nil || err != nil { return nil, 0, false, err } diff --git a/les/api_backend.go b/les/api_backend.go index 4c6ee1f7a7..8333fdd8c3 100644 --- a/les/api_backend.go +++ b/les/api_backend.go @@ -19,7 +19,6 @@ package les import ( "context" "errors" - "fmt" "math/big" "github.com/maticnetwork/bor/accounts" @@ -61,10 +60,8 @@ func (b *LesApiBackend) SetHead(number uint64) { func (b *LesApiBackend) HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Header, error) { if blockNr == rpc.LatestBlockNumber || blockNr == rpc.PendingBlockNumber { - fmt.Println("20") return b.eth.blockchain.CurrentHeader(), nil } - fmt.Println("21") return b.eth.blockchain.GetHeaderByNumberOdr(ctx, uint64(blockNr)) }