diff --git a/consensus/clique/clique.go b/consensus/clique/clique.go index 546171ec72..790c47122c 100644 --- a/consensus/clique/clique.go +++ b/consensus/clique/clique.go @@ -27,6 +27,7 @@ import ( "sync" "time" + lru "github.com/hashicorp/golang-lru" "github.com/spruce-solutions/go-quai/accounts" "github.com/spruce-solutions/go-quai/common" "github.com/spruce-solutions/go-quai/common/hexutil" @@ -41,7 +42,6 @@ import ( "github.com/spruce-solutions/go-quai/rlp" "github.com/spruce-solutions/go-quai/rpc" "github.com/spruce-solutions/go-quai/trie" - lru "github.com/hashicorp/golang-lru" "golang.org/x/crypto/sha3" ) @@ -592,7 +592,7 @@ func (c *Clique) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header * } // GetExternalBlocks traces all available branches to find external blocks -func (c *Clique) GetExternalBlocks(chain consensus.ChainHeaderReader, header *types.Header) []*types.ExternalBlock { +func (c *Clique) GetExternalBlocks(chain consensus.ChainHeaderReader, header *types.Header, logging bool) []*types.ExternalBlock { return make([]*types.ExternalBlock, 0) } @@ -607,7 +607,7 @@ func (c *Clique) GetStopHash(chain consensus.ChainHeaderReader, difficultyContex } // TraceBranch recursively traces branches to find -func (c *Clique) TraceBranch(chain consensus.ChainHeaderReader, header *types.Header, context int, stopHash common.Hash, originalContext int, originalLocation []byte) []*types.ExternalBlock { +func (c *Clique) TraceBranch(chain consensus.ChainHeaderReader, header *types.Header, context int, stopHash common.Hash, originalContext int, originalLocation []byte, logging bool) []*types.ExternalBlock { return make([]*types.ExternalBlock, 0) } diff --git a/consensus/consensus.go b/consensus/consensus.go index f4f8184c4b..4bc0b2974c 100644 --- a/consensus/consensus.go +++ b/consensus/consensus.go @@ -104,7 +104,7 @@ type Engine interface { uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) // GetExternalBlocks retrieves all valid external blocks from external chains - GetExternalBlocks(chain ChainHeaderReader, header *types.Header) []*types.ExternalBlock + GetExternalBlocks(chain ChainHeaderReader, header *types.Header, logging bool) []*types.ExternalBlock // GetCoincidentHeader retrieves the furthest coincident header back GetCoincidentHeader(chain ChainHeaderReader, context int, header *types.Header) (*types.Header, int) @@ -113,7 +113,7 @@ type Engine interface { GetStopHash(chain ChainHeaderReader, difficultyContext int, originalContext int, startingHeader *types.Header) common.Hash // TraceBranch recursively traces branches to find - TraceBranch(chain ChainHeaderReader, header *types.Header, context int, stopHash common.Hash, originalContext int, originalLocation []byte) []*types.ExternalBlock + TraceBranch(chain ChainHeaderReader, header *types.Header, context int, stopHash common.Hash, originalContext int, originalLocation []byte, logging bool) []*types.ExternalBlock // Seal generates a new sealing request for the given input block and pushes // the result into the given channel. diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go index 416cc44c29..835018306a 100644 --- a/consensus/ethash/consensus.go +++ b/consensus/ethash/consensus.go @@ -750,7 +750,7 @@ func (ethash *Ethash) GetStopHash(chain consensus.ChainHeaderReader, difficultyC return stopHash } -func (ethash *Ethash) TraceBranch(chain consensus.ChainHeaderReader, header *types.Header, context int, stopHash common.Hash, originalContext int, originalLocation []byte) []*types.ExternalBlock { +func (ethash *Ethash) TraceBranch(chain consensus.ChainHeaderReader, header *types.Header, context int, stopHash common.Hash, originalContext int, originalLocation []byte, logging bool) []*types.ExternalBlock { extBlocks := make([]*types.ExternalBlock, 0) steppedBack := false startingHeader := header @@ -764,7 +764,9 @@ func (ethash *Ethash) TraceBranch(chain consensus.ChainHeaderReader, header *typ // If we have reached a coincident block or we're in Region and found the prev region if difficultyContext < context && steppedBack { - log.Info("TraceBranch: Found coincident block", "number", header.Number, "context", context, "location", header.Location) + if logging { + log.Info("TraceBranch: Found coincident block", "number", header.Number, "context", context, "location", header.Location) + } break } @@ -782,17 +784,21 @@ func (ethash *Ethash) TraceBranch(chain consensus.ChainHeaderReader, header *typ log.Warn("TraceBranch: External Block not found for header", "number", header.Number[context], "context", context) break } - log.Info("GetExternalBlocks: Block being added: ", "number", extBlock.Header().Number, "context", extBlock.Context(), "location", extBlock.Header().Location, "txs", len(extBlock.Transactions())) + if logging { + log.Info("GetExternalBlocks: Block being added: ", "number", extBlock.Header().Number, "context", extBlock.Context(), "location", extBlock.Header().Location, "txs", len(extBlock.Transactions())) + } extBlocks = append(extBlocks, extBlock) } if context < types.ContextDepth-1 { - extBlocks = append(extBlocks, ethash.TraceBranch(chain, header, context+1, stopHash, originalContext, originalLocation)...) + extBlocks = append(extBlocks, ethash.TraceBranch(chain, header, context+1, stopHash, originalContext, originalLocation, logging)...) } // Stop at the stop hash before iterating downward if header.ParentHash[context] == stopHash || header.Number[context].Cmp(big.NewInt(1)) <= 0 { - log.Info("TraceBranch: Stopping on stop hash", "number", header.Number, "context", context, "location", header.Location) + if logging { + log.Info("TraceBranch: Stopping on stop hash", "number", header.Number, "context", context, "location", header.Location) + } break } @@ -808,7 +814,10 @@ func (ethash *Ethash) TraceBranch(chain consensus.ChainHeaderReader, header *typ } prevHeader = extBlock.Header() // In Regions the starting header needs to be broken off for N-1 - if context < types.ContextDepth-1 && bytes.Equal(startingHeader.Location, prevHeader.Location) && originalContext != 0 { + if context < types.ContextDepth-1 && bytes.Equal(startingHeader.Location, prevHeader.Location) && originalContext != 0 && sameLocation { + if logging { + log.Info("TraceBranch: Stopping with Region N-1", "number", header.Number, "context", context, "location", header.Location) + } break } } @@ -819,7 +828,7 @@ func (ethash *Ethash) TraceBranch(chain consensus.ChainHeaderReader, header *typ } // GetExternalBlocks traces all available branches to find external blocks -func (ethash *Ethash) GetExternalBlocks(chain consensus.ChainHeaderReader, header *types.Header) []*types.ExternalBlock { +func (ethash *Ethash) GetExternalBlocks(chain consensus.ChainHeaderReader, header *types.Header, logging bool) []*types.ExternalBlock { context := chain.Config().Context // Index that node is currently at externalBlocks := make([]*types.ExternalBlock, 0) @@ -833,7 +842,7 @@ func (ethash *Ethash) GetExternalBlocks(chain consensus.ChainHeaderReader, heade return externalBlocks } stopHash := ethash.GetStopHash(chain, difficultyContext, context, coincidentHeader) - externalBlocks = append(externalBlocks, ethash.TraceBranch(chain, coincidentHeader, difficultyContext, stopHash, context, header.Location)...) + externalBlocks = append(externalBlocks, ethash.TraceBranch(chain, coincidentHeader, difficultyContext, stopHash, context, header.Location, logging)...) } // Swap order of external blocks diff --git a/core/blockchain.go b/core/blockchain.go index 175c8350bc..aa7274aee7 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -30,6 +30,7 @@ import ( "time" "github.com/VictoriaMetrics/fastcache" + lru "github.com/hashicorp/golang-lru" "github.com/spruce-solutions/go-quai/common" "github.com/spruce-solutions/go-quai/common/mclock" "github.com/spruce-solutions/go-quai/common/prque" @@ -46,7 +47,6 @@ import ( "github.com/spruce-solutions/go-quai/params" "github.com/spruce-solutions/go-quai/rlp" "github.com/spruce-solutions/go-quai/trie" - lru "github.com/hashicorp/golang-lru" ) var ( @@ -2505,7 +2505,7 @@ func (bc *BlockChain) GetExternalBlocks(header *types.Header) ([]*types.External return externalBlocks, nil } stopHash := bc.engine.GetStopHash(bc, difficultyContext, context, coincidentHeader) - externalBlocks = append(externalBlocks, bc.engine.TraceBranch(bc, coincidentHeader, difficultyContext, stopHash, context, header.Location)...) + externalBlocks = append(externalBlocks, bc.engine.TraceBranch(bc, coincidentHeader, difficultyContext, stopHash, context, header.Location, false)...) } return externalBlocks, nil diff --git a/core/state_processor.go b/core/state_processor.go index 8e4a67ea99..e7cc799fcb 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -77,16 +77,14 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg // Gather external blocks and apply transactions, need to trace own local external block cache based on cache to validate i := 0 - externalBlocks := p.engine.GetExternalBlocks(p.bc, header) + externalBlocks := p.engine.GetExternalBlocks(p.bc, header, true) etxs := 0 for _, externalBlock := range externalBlocks { externalBlock.Receipts().DeriveFields(p.config, externalBlock.Hash(), externalBlock.Header().Number[externalBlock.Context().Int64()].Uint64(), externalBlock.Transactions()) - etxs += len(externalBlock.Transactions()) for _, tx := range externalBlock.Transactions() { msg, err := tx.AsMessage(types.MakeSigner(p.config, header.Number[types.QuaiNetworkContext]), header.BaseFee[types.QuaiNetworkContext]) // Quick check to make sure we're adding an external transaction, currently saves us from not passing merkel path in external block if !msg.FromExternal() { - log.Info("Process: Message is not from an external address", "from", msg.From()) continue } if err != nil { @@ -99,6 +97,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg } receipts = append(receipts, receipt) allLogs = append(allLogs, receipt.Logs...) + etxs += 1 i++ } } diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index 009e5da29f..4edb47775b 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -24,7 +24,7 @@ import ( "fmt" "math/big" - "github.com/spruce-solutions/go-quai" + ethereum "github.com/spruce-solutions/go-quai" "github.com/spruce-solutions/go-quai/common" "github.com/spruce-solutions/go-quai/common/hexutil" "github.com/spruce-solutions/go-quai/core/types" @@ -163,7 +163,7 @@ func (ec *Client) getBlockWithReceipts(ctx context.Context, method string, args return nil, reqs[i].Error } if uncles[i] == nil { - return nil, fmt.Errorf("getBlockWithReceipts: got null header for uncle %d of block %x", i, body.Hash[:]) + return nil, fmt.Errorf("getBlockWithReceipts: got null header for uncle %d with hash %x", i, body.UncleHashes[i]) } } } diff --git a/miner/worker.go b/miner/worker.go index ffa2c475eb..10dd916d82 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -993,7 +993,7 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64) } // Gather external blocks and apply transactions - externalBlocks := w.engine.GetExternalBlocks(w.chain, header) + externalBlocks := w.engine.GetExternalBlocks(w.chain, header, false) etxs := make(types.Transactions, 0) for _, externalBlock := range externalBlocks { externalBlock.Receipts().DeriveFields(w.chainConfig, externalBlock.Hash(), externalBlock.Header().Number[externalBlock.Context().Int64()].Uint64(), externalBlock.Transactions())