From e8decf24bc7b95f0de90298ff0f3b5a6168771b0 Mon Sep 17 00:00:00 2001 From: Milos Zivkovic Date: Tue, 2 Aug 2022 12:04:34 +0200 Subject: [PATCH 1/4] Add proper header copying --- .gitignore | 5 ++++- types/header.go | 45 ++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index ad25df88e0..d09551aa60 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,7 @@ main .vscode # exclude build folder -artifacts \ No newline at end of file +artifacts + +# Log files +*.log \ No newline at end of file diff --git a/types/header.go b/types/header.go index 40c04f630b..674db02590 100644 --- a/types/header.go +++ b/types/header.go @@ -182,13 +182,48 @@ func (n *Nonce) UnmarshalText(input []byte) error { } func (h *Header) Copy() *Header { - hh := new(Header) - *hh = *h + newHeader := &Header{ + Difficulty: h.Difficulty, + Number: h.Number, + GasLimit: h.GasLimit, + GasUsed: h.GasUsed, + Timestamp: h.Timestamp, + } + + newHeader.ParentHash = Hash{} + copy(newHeader.ParentHash[:], h.ParentHash[:]) + + newHeader.Sha3Uncles = Hash{} + copy(newHeader.Sha3Uncles[:], h.Sha3Uncles[:]) + + newHeader.Miner = Address{} + copy(newHeader.Miner[:], h.Miner[:]) + + newHeader.StateRoot = Hash{} + copy(newHeader.StateRoot[:], h.StateRoot[:]) + + newHeader.TxRoot = Hash{} + copy(newHeader.TxRoot[:], h.TxRoot[:]) + + newHeader.ReceiptsRoot = Hash{} + copy(newHeader.ReceiptsRoot[:], h.ReceiptsRoot[:]) + + newHeader.MixHash = Hash{} + copy(newHeader.MixHash[:], h.MixHash[:]) + + newHeader.Hash = Hash{} + copy(newHeader.Hash[:], h.Hash[:]) + + newHeader.LogsBloom = Bloom{} + copy(newHeader.LogsBloom[:], h.LogsBloom[:]) + + newHeader.Nonce = Nonce{} + copy(newHeader.Nonce[:], h.Nonce[:]) - hh.ExtraData = make([]byte, len(h.ExtraData)) - copy(hh.ExtraData[:], h.ExtraData[:]) + newHeader.ExtraData = make([]byte, len(h.ExtraData)) + copy(newHeader.ExtraData[:], h.ExtraData[:]) - return hh + return newHeader } type Body struct { From 7455df18123f2f5f8e7467d0f529f97b2d57581d Mon Sep 17 00:00:00 2001 From: Milos Zivkovic Date: Tue, 2 Aug 2022 12:05:29 +0200 Subject: [PATCH 2/4] Enable pprof --- jsonrpc/jsonrpc.go | 1 + 1 file changed, 1 insertion(+) diff --git a/jsonrpc/jsonrpc.go b/jsonrpc/jsonrpc.go index 1009effbab..19d9141e34 100644 --- a/jsonrpc/jsonrpc.go +++ b/jsonrpc/jsonrpc.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "net" "net/http" + _ "net/http/pprof" "sync" "time" From 24f9619284bc47fe6d638b47b0220995c9846130 Mon Sep 17 00:00:00 2001 From: Milos Zivkovic Date: Fri, 5 Aug 2022 12:48:08 +0200 Subject: [PATCH 3/4] Remove leftover pprof import --- jsonrpc/jsonrpc.go | 1 - 1 file changed, 1 deletion(-) diff --git a/jsonrpc/jsonrpc.go b/jsonrpc/jsonrpc.go index 19d9141e34..1009effbab 100644 --- a/jsonrpc/jsonrpc.go +++ b/jsonrpc/jsonrpc.go @@ -5,7 +5,6 @@ import ( "io/ioutil" "net" "net/http" - _ "net/http/pprof" "sync" "time" From 8f37291450514147e2726b137ca7f278adaf6aab Mon Sep 17 00:00:00 2001 From: Milos Zivkovic Date: Fri, 5 Aug 2022 13:11:14 +0200 Subject: [PATCH 4/4] Simplify copying --- types/header.go | 50 +++++++++++++++---------------------------------- 1 file changed, 15 insertions(+), 35 deletions(-) diff --git a/types/header.go b/types/header.go index 674db02590..5c63cbc8e4 100644 --- a/types/header.go +++ b/types/header.go @@ -183,43 +183,23 @@ func (n *Nonce) UnmarshalText(input []byte) error { func (h *Header) Copy() *Header { newHeader := &Header{ - Difficulty: h.Difficulty, - Number: h.Number, - GasLimit: h.GasLimit, - GasUsed: h.GasUsed, - Timestamp: h.Timestamp, + ParentHash: h.ParentHash, + Sha3Uncles: h.Sha3Uncles, + Miner: h.Miner, + StateRoot: h.StateRoot, + TxRoot: h.TxRoot, + ReceiptsRoot: h.ReceiptsRoot, + MixHash: h.MixHash, + Hash: h.Hash, + LogsBloom: h.LogsBloom, + Nonce: h.Nonce, + Difficulty: h.Difficulty, + Number: h.Number, + GasLimit: h.GasLimit, + GasUsed: h.GasUsed, + Timestamp: h.Timestamp, } - newHeader.ParentHash = Hash{} - copy(newHeader.ParentHash[:], h.ParentHash[:]) - - newHeader.Sha3Uncles = Hash{} - copy(newHeader.Sha3Uncles[:], h.Sha3Uncles[:]) - - newHeader.Miner = Address{} - copy(newHeader.Miner[:], h.Miner[:]) - - newHeader.StateRoot = Hash{} - copy(newHeader.StateRoot[:], h.StateRoot[:]) - - newHeader.TxRoot = Hash{} - copy(newHeader.TxRoot[:], h.TxRoot[:]) - - newHeader.ReceiptsRoot = Hash{} - copy(newHeader.ReceiptsRoot[:], h.ReceiptsRoot[:]) - - newHeader.MixHash = Hash{} - copy(newHeader.MixHash[:], h.MixHash[:]) - - newHeader.Hash = Hash{} - copy(newHeader.Hash[:], h.Hash[:]) - - newHeader.LogsBloom = Bloom{} - copy(newHeader.LogsBloom[:], h.LogsBloom[:]) - - newHeader.Nonce = Nonce{} - copy(newHeader.Nonce[:], h.Nonce[:]) - newHeader.ExtraData = make([]byte, len(h.ExtraData)) copy(newHeader.ExtraData[:], h.ExtraData[:])