mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 03:30:37 +00:00
rename ReadBody to ReadBodyWithTransactions to make it obvious that it's heavier then just ReadBody (#2534)
* rename ReadBody to ReadBodyWithTransactions * rename ReadBody to ReadBodyWithTransactions
This commit is contained in:
parent
cacc4c7e3b
commit
c7c3a5932a
@ -858,7 +858,7 @@ func validateTxLookups2(db kv.RwDB, startBlock uint64, interruptCh chan bool) {
|
||||
for !interrupt {
|
||||
blockHash, err := rawdb.ReadCanonicalHash(tx, blockNum)
|
||||
tool.Check(err)
|
||||
body := rawdb.ReadBody(tx, blockHash, blockNum)
|
||||
body := rawdb.ReadBodyWithTransactions(tx, blockHash, blockNum)
|
||||
|
||||
if body == nil {
|
||||
break
|
||||
@ -1456,7 +1456,7 @@ func mint(chaindata string, block uint64) error {
|
||||
fmt.Printf("Gap [%d-%d]\n", prevBlock, blockNumber-1)
|
||||
}
|
||||
prevBlock = blockNumber
|
||||
body := rawdb.ReadBody(tx, blockHash, blockNumber)
|
||||
body := rawdb.ReadBodyWithTransactions(tx, blockHash, blockNumber)
|
||||
header := rawdb.ReadHeader(tx, blockHash, blockNumber)
|
||||
senders, errSenders := rawdb.ReadSenders(tx, blockHash, blockNumber)
|
||||
if errSenders != nil {
|
||||
@ -1580,7 +1580,7 @@ func extractBodies(chaindata string, block uint64) error {
|
||||
}
|
||||
blockNumber := binary.BigEndian.Uint64(k[:8])
|
||||
blockHash := common.BytesToHash(k[8:])
|
||||
_, baseTxId, txAmount := rawdb.ReadBodyWithoutTransactions(tx, blockHash, blockNumber)
|
||||
_, baseTxId, txAmount := rawdb.ReadBody(tx, blockHash, blockNumber)
|
||||
fmt.Printf("Body %d %x: baseTxId %d, txAmount %d\n", blockNumber, blockHash, baseTxId, txAmount)
|
||||
}
|
||||
return nil
|
||||
@ -2156,7 +2156,7 @@ func scanReceipts(chaindata string, block uint64) error {
|
||||
}
|
||||
var body *types.Body
|
||||
if chainConfig.IsBerlin(blockNum) {
|
||||
body = rawdb.ReadBody(tx, hash, blockNum)
|
||||
body = rawdb.ReadBodyWithTransactions(tx, hash, blockNum)
|
||||
}
|
||||
receipts = make(types.Receipts, len(oldReceipts))
|
||||
for i, oldReceipt := range oldReceipts {
|
||||
|
@ -285,7 +285,7 @@ func (api *APIImpl) GetBlockTransactionCountByHash(ctx context.Context, blockHas
|
||||
if num == nil {
|
||||
return nil, nil
|
||||
}
|
||||
body, _, txAmount := rawdb.ReadBodyWithoutTransactions(tx, blockHash, *num)
|
||||
body, _, txAmount := rawdb.ReadBody(tx, blockHash, *num)
|
||||
if body == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ func TestSendRawTransaction(t *testing.T) {
|
||||
|
||||
initialCycle := true
|
||||
highestSeenHeader := chain.TopBlock.NumberU64()
|
||||
if err := stages.StageLoopStep(m.Ctx, m.Log, m.DB, m.Sync, highestSeenHeader, m.Notifications, initialCycle, m.UpdateHead, nil); err != nil {
|
||||
if err := stages.StageLoopStep(m.Ctx, m.DB, m.Sync, highestSeenHeader, m.Notifications, initialCycle, m.UpdateHead, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ func TestTxPoolContent(t *testing.T) {
|
||||
|
||||
initialCycle := true
|
||||
highestSeenHeader := chain.TopBlock.NumberU64()
|
||||
if err := stages.StageLoopStep(m.Ctx, m.Log, m.DB, m.Sync, highestSeenHeader, m.Notifications, initialCycle, m.UpdateHead, nil); err != nil {
|
||||
if err := stages.StageLoopStep(m.Ctx, m.DB, m.Sync, highestSeenHeader, m.Notifications, initialCycle, m.UpdateHead, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ func ValidateTxLookups(chaindata string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
body := rawdb.ReadBody(tx, blockHash, blockNum)
|
||||
body := rawdb.ReadBodyWithTransactions(tx, blockHash, blockNum)
|
||||
|
||||
if body == nil {
|
||||
log.Error("Empty body", "blocknum", blockNum)
|
||||
|
@ -243,7 +243,7 @@ func DeleteHeader(db kv.Deleter, hash common.Hash, number uint64) {
|
||||
|
||||
// ReadBodyRLP retrieves the block body (transactions and uncles) in RLP encoding.
|
||||
func ReadBodyRLP(db kv.Tx, hash common.Hash, number uint64) rlp.RawValue {
|
||||
body := ReadBody(db, hash, number)
|
||||
body := ReadBodyWithTransactions(db, hash, number)
|
||||
bodyRlp, err := rlp.EncodeToBytes(body)
|
||||
if err != nil {
|
||||
log.Error("ReadBodyRLP failed", "err", err)
|
||||
@ -356,12 +356,12 @@ func ReadBodyByNumber(db kv.Tx, number uint64) (*types.Body, uint64, uint32, err
|
||||
if hash == (common.Hash{}) {
|
||||
return nil, 0, 0, nil
|
||||
}
|
||||
body, baseTxId, txAmount := ReadBodyWithoutTransactions(db, hash, number)
|
||||
body, baseTxId, txAmount := ReadBody(db, hash, number)
|
||||
return body, baseTxId, txAmount, nil
|
||||
}
|
||||
|
||||
func ReadBody(db kv.Getter, hash common.Hash, number uint64) *types.Body {
|
||||
body, baseTxId, txAmount := ReadBodyWithoutTransactions(db, hash, number)
|
||||
func ReadBodyWithTransactions(db kv.Getter, hash common.Hash, number uint64) *types.Body {
|
||||
body, baseTxId, txAmount := ReadBody(db, hash, number)
|
||||
if body == nil {
|
||||
return nil
|
||||
}
|
||||
@ -374,7 +374,7 @@ func ReadBody(db kv.Getter, hash common.Hash, number uint64) *types.Body {
|
||||
return body
|
||||
}
|
||||
|
||||
func ReadBodyWithoutTransactions(db kv.Getter, hash common.Hash, number uint64) (*types.Body, uint64, uint32) {
|
||||
func ReadBody(db kv.Getter, hash common.Hash, number uint64) (*types.Body, uint64, uint32) {
|
||||
data := ReadStorageBodyRLP(db, hash, number)
|
||||
if len(data) == 0 {
|
||||
return nil, 0, 0
|
||||
@ -716,7 +716,7 @@ func ReadBlock(tx kv.Getter, hash common.Hash, number uint64) *types.Block {
|
||||
if header == nil {
|
||||
return nil
|
||||
}
|
||||
body := ReadBody(tx, hash, number)
|
||||
body := ReadBodyWithTransactions(tx, hash, number)
|
||||
if body == nil {
|
||||
return nil
|
||||
}
|
||||
|
@ -96,11 +96,11 @@ func TestBodyStorage(t *testing.T) {
|
||||
_ = rlp.Encode(hasher, body)
|
||||
hash := common.BytesToHash(hasher.Sum(nil))
|
||||
|
||||
if entry := ReadBody(tx, hash, 0); entry != nil {
|
||||
if entry := ReadBodyWithTransactions(tx, hash, 0); entry != nil {
|
||||
t.Fatalf("Non existent body returned: %v", entry)
|
||||
}
|
||||
require.NoError(WriteBody(tx, hash, 0, body))
|
||||
if entry := ReadBody(tx, hash, 0); entry == nil {
|
||||
if entry := ReadBodyWithTransactions(tx, hash, 0); entry == nil {
|
||||
t.Fatalf("Stored body not found")
|
||||
} else if types.DeriveSha(types.Transactions(entry.Transactions)) != types.DeriveSha(types.Transactions(body.Transactions)) || types.CalcUncleHash(entry.Uncles) != types.CalcUncleHash(body.Uncles) {
|
||||
t.Fatalf("Retrieved body mismatch: have %v, want %v", entry, body)
|
||||
@ -117,7 +117,7 @@ func TestBodyStorage(t *testing.T) {
|
||||
}
|
||||
// Delete the body and verify the execution
|
||||
DeleteBody(tx, hash, 0)
|
||||
if entry := ReadBody(tx, hash, 0); entry != nil {
|
||||
if entry := ReadBodyWithTransactions(tx, hash, 0); entry != nil {
|
||||
t.Fatalf("Deleted body returned: %v", entry)
|
||||
}
|
||||
}
|
||||
@ -139,7 +139,7 @@ func TestBlockStorage(t *testing.T) {
|
||||
if entry := ReadHeader(tx, block.Hash(), block.NumberU64()); entry != nil {
|
||||
t.Fatalf("Non existent header returned: %v", entry)
|
||||
}
|
||||
if entry := ReadBody(tx, block.Hash(), block.NumberU64()); entry != nil {
|
||||
if entry := ReadBodyWithTransactions(tx, block.Hash(), block.NumberU64()); entry != nil {
|
||||
t.Fatalf("Non existent body returned: %v", entry)
|
||||
}
|
||||
// Write and verify the block in the database
|
||||
@ -157,7 +157,7 @@ func TestBlockStorage(t *testing.T) {
|
||||
} else if entry.Hash() != block.Header().Hash() {
|
||||
t.Fatalf("Retrieved header mismatch: have %v, want %v", entry, block.Header())
|
||||
}
|
||||
if entry := ReadBody(tx, block.Hash(), block.NumberU64()); entry == nil {
|
||||
if entry := ReadBodyWithTransactions(tx, block.Hash(), block.NumberU64()); entry == nil {
|
||||
t.Fatalf("Stored body not found")
|
||||
} else if types.DeriveSha(types.Transactions(entry.Transactions)) != types.DeriveSha(block.Transactions()) || types.CalcUncleHash(entry.Uncles) != types.CalcUncleHash(block.Uncles()) {
|
||||
t.Fatalf("Retrieved body mismatch: have %v, want %v", entry, block.Body())
|
||||
@ -172,7 +172,7 @@ func TestBlockStorage(t *testing.T) {
|
||||
if entry := ReadHeader(tx, block.Hash(), block.NumberU64()); entry != nil {
|
||||
t.Fatalf("Deleted header returned: %v", entry)
|
||||
}
|
||||
if entry := ReadBody(tx, block.Hash(), block.NumberU64()); entry != nil {
|
||||
if entry := ReadBodyWithTransactions(tx, block.Hash(), block.NumberU64()); entry != nil {
|
||||
t.Fatalf("Deleted body returned: %v", entry)
|
||||
}
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ func ReadTransaction(db kv.Tx, hash common.Hash) (types.Transaction, common.Hash
|
||||
if blockHash == (common.Hash{}) {
|
||||
return nil, common.Hash{}, 0, 0, nil
|
||||
}
|
||||
body := ReadBody(db, blockHash, *blockNumber)
|
||||
body := ReadBodyWithTransactions(db, blockHash, *blockNumber)
|
||||
if body == nil {
|
||||
log.Error("Transaction referenced missing", "number", blockNumber, "hash", blockHash)
|
||||
return nil, common.Hash{}, 0, 0, nil
|
||||
|
@ -678,12 +678,7 @@ func (s *Ethereum) Start() error {
|
||||
}(i)
|
||||
}
|
||||
|
||||
go stages2.StageLoop(
|
||||
s.downloadCtx, s.logger, s.chainKV,
|
||||
s.stagedSync, s.downloadServer.Hd,
|
||||
s.notifications, s.downloadServer.UpdateHead, s.waitForStageLoopStop,
|
||||
s.config.SyncLoopThrottle,
|
||||
)
|
||||
go stages2.StageLoop(s.downloadCtx, s.chainKV, s.stagedSync, s.downloadServer.Hd, s.notifications, s.downloadServer.UpdateHead, s.waitForStageLoopStop, s.config.SyncLoopThrottle)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -167,11 +167,10 @@ func promoteHistory(logPrefix string, tx kv.RwTx, changesetBucket string, start,
|
||||
}
|
||||
}
|
||||
|
||||
kStr := string(k)
|
||||
m, ok := updates[kStr]
|
||||
m, ok := updates[string(k)]
|
||||
if !ok {
|
||||
m = roaring64.New()
|
||||
updates[kStr] = m
|
||||
updates[string(k)] = m
|
||||
}
|
||||
m.Add(blockN)
|
||||
|
||||
|
@ -206,7 +206,7 @@ Loop:
|
||||
// non-canonical case
|
||||
continue
|
||||
}
|
||||
body := rawdb.ReadBody(tx, blockHash, blockNumber)
|
||||
body := rawdb.ReadBodyWithTransactions(tx, blockHash, blockNumber)
|
||||
|
||||
select {
|
||||
case recoveryErr := <-errCh:
|
||||
|
@ -112,13 +112,13 @@ func TestSenders(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
|
||||
{
|
||||
found := rawdb.ReadBody(tx, common.HexToHash("01"), 1)
|
||||
found := rawdb.ReadBodyWithTransactions(tx, common.HexToHash("01"), 1)
|
||||
assert.NotNil(t, found)
|
||||
assert.Equal(t, 2, len(found.Transactions))
|
||||
found = rawdb.ReadBody(tx, common.HexToHash("02"), 2)
|
||||
found = rawdb.ReadBodyWithTransactions(tx, common.HexToHash("02"), 2)
|
||||
assert.NotNil(t, found)
|
||||
assert.NotNil(t, 3, len(found.Transactions))
|
||||
found = rawdb.ReadBody(tx, common.HexToHash("03"), 3)
|
||||
found = rawdb.ReadBodyWithTransactions(tx, common.HexToHash("03"), 3)
|
||||
assert.NotNil(t, found)
|
||||
assert.NotNil(t, 0, len(found.Transactions))
|
||||
assert.NotNil(t, 2, len(found.Uncles))
|
||||
|
@ -80,7 +80,7 @@ func TxLookupTransform(logPrefix string, tx kv.RwTx, startKey, endKey []byte, qu
|
||||
return etl.Transform(logPrefix, tx, kv.HeaderCanonical, kv.TxLookup, cfg.tmpdir, func(k []byte, v []byte, next etl.ExtractNextFunc) error {
|
||||
blocknum := binary.BigEndian.Uint64(k)
|
||||
blockHash := common.BytesToHash(v)
|
||||
body := rawdb.ReadBody(tx, blockHash, blocknum)
|
||||
body := rawdb.ReadBodyWithTransactions(tx, blockHash, blocknum)
|
||||
if body == nil {
|
||||
return fmt.Errorf("empty block body %d, hash %x", blocknum, v)
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ func incrementalTxPoolUpdate(logPrefix string, from, to uint64, pool *core.TxPoo
|
||||
continue
|
||||
}
|
||||
|
||||
body := rawdb.ReadBody(tx, blockHash, blockNumber)
|
||||
body := rawdb.ReadBodyWithTransactions(tx, blockHash, blockNumber)
|
||||
for _, tx := range body.Transactions {
|
||||
pool.RemoveTx(tx.Hash(), true /* outofbound */)
|
||||
}
|
||||
@ -267,7 +267,7 @@ func unwindTxPoolUpdate(logPrefix string, from, to uint64, pool *core.TxPool, tx
|
||||
continue
|
||||
}
|
||||
|
||||
body := rawdb.ReadBody(tx, blockHash, blockNumber)
|
||||
body := rawdb.ReadBodyWithTransactions(tx, blockHash, blockNumber)
|
||||
body.SendersToTxs(senders[blockNumber-from-1])
|
||||
txsToInject = append(txsToInject, body.Transactions...)
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ var ReceiptCbor = Migration{
|
||||
}
|
||||
var body *types.Body
|
||||
if chainConfig.IsBerlin(blockNum) {
|
||||
body = rawdb.ReadBody(tx, blockHash, blockNum)
|
||||
body = rawdb.ReadBodyWithTransactions(tx, blockHash, blockNum)
|
||||
}
|
||||
receipts = make(types.Receipts, len(oldReceipts))
|
||||
for i, oldReceipt := range oldReceipts {
|
||||
|
@ -418,7 +418,7 @@ func (ms *MockSentry) InsertChain(chain *core.ChainPack) error {
|
||||
ms.ReceiveWg.Wait() // Wait for all messages to be processed before we proceeed
|
||||
initialCycle := false
|
||||
highestSeenHeader := chain.TopBlock.NumberU64()
|
||||
if err := StageLoopStep(ms.Ctx, ms.Log, ms.DB, ms.Sync, highestSeenHeader, ms.Notifications, initialCycle, ms.UpdateHead, nil); err != nil {
|
||||
if err := StageLoopStep(ms.Ctx, ms.DB, ms.Sync, highestSeenHeader, ms.Notifications, initialCycle, ms.UpdateHead, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
// Check if the latest header was imported or rolled back
|
||||
|
@ -57,7 +57,7 @@ func TestHeaderStep(t *testing.T) {
|
||||
|
||||
initialCycle := true
|
||||
highestSeenHeader := uint64(chain.TopBlock.NumberU64())
|
||||
if err := stages.StageLoopStep(m.Ctx, m.Log, m.DB, m.Sync, highestSeenHeader, m.Notifications, initialCycle, m.UpdateHead, nil); err != nil {
|
||||
if err := stages.StageLoopStep(m.Ctx, m.DB, m.Sync, highestSeenHeader, m.Notifications, initialCycle, m.UpdateHead, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@ -98,7 +98,7 @@ func TestMineBlockWith1Tx(t *testing.T) {
|
||||
|
||||
initialCycle := true
|
||||
highestSeenHeader := uint64(chain.TopBlock.NumberU64())
|
||||
if err := stages.StageLoopStep(m.Ctx, m.Log, m.DB, m.Sync, highestSeenHeader, m.Notifications, initialCycle, m.UpdateHead, nil); err != nil {
|
||||
if err := stages.StageLoopStep(m.Ctx, m.DB, m.Sync, highestSeenHeader, m.Notifications, initialCycle, m.UpdateHead, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@ -169,7 +169,7 @@ func TestReorg(t *testing.T) {
|
||||
|
||||
initialCycle := true
|
||||
highestSeenHeader := uint64(chain.TopBlock.NumberU64())
|
||||
if err := stages.StageLoopStep(m.Ctx, m.Log, m.DB, m.Sync, highestSeenHeader, m.Notifications, initialCycle, m.UpdateHead, nil); err != nil {
|
||||
if err := stages.StageLoopStep(m.Ctx, m.DB, m.Sync, highestSeenHeader, m.Notifications, initialCycle, m.UpdateHead, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@ -223,7 +223,7 @@ func TestReorg(t *testing.T) {
|
||||
|
||||
highestSeenHeader = uint64(short.TopBlock.NumberU64())
|
||||
initialCycle = false
|
||||
if err := stages.StageLoopStep(m.Ctx, m.Log, m.DB, m.Sync, highestSeenHeader, m.Notifications, initialCycle, m.UpdateHead, nil); err != nil {
|
||||
if err := stages.StageLoopStep(m.Ctx, m.DB, m.Sync, highestSeenHeader, m.Notifications, initialCycle, m.UpdateHead, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@ -267,7 +267,7 @@ func TestReorg(t *testing.T) {
|
||||
|
||||
// This is unwind step
|
||||
highestSeenHeader = uint64(long1.TopBlock.NumberU64())
|
||||
if err := stages.StageLoopStep(m.Ctx, m.Log, m.DB, m.Sync, highestSeenHeader, m.Notifications, initialCycle, m.UpdateHead, nil); err != nil {
|
||||
if err := stages.StageLoopStep(m.Ctx, m.DB, m.Sync, highestSeenHeader, m.Notifications, initialCycle, m.UpdateHead, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@ -305,7 +305,7 @@ func TestReorg(t *testing.T) {
|
||||
|
||||
highestSeenHeader = uint64(short2.TopBlock.NumberU64())
|
||||
initialCycle = false
|
||||
if err := stages.StageLoopStep(m.Ctx, m.Log, m.DB, m.Sync, highestSeenHeader, m.Notifications, initialCycle, m.UpdateHead, nil); err != nil {
|
||||
if err := stages.StageLoopStep(m.Ctx, m.DB, m.Sync, highestSeenHeader, m.Notifications, initialCycle, m.UpdateHead, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@ -404,7 +404,7 @@ func TestAnchorReplace(t *testing.T) {
|
||||
|
||||
highestSeenHeader := uint64(long.TopBlock.NumberU64())
|
||||
initialCycle := true
|
||||
if err := stages.StageLoopStep(m.Ctx, m.Log, m.DB, m.Sync, highestSeenHeader, m.Notifications, initialCycle, m.UpdateHead, nil); err != nil {
|
||||
if err := stages.StageLoopStep(m.Ctx, m.DB, m.Sync, highestSeenHeader, m.Notifications, initialCycle, m.UpdateHead, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@ -511,7 +511,7 @@ func TestAnchorReplace2(t *testing.T) {
|
||||
|
||||
highestSeenHeader := uint64(long.TopBlock.NumberU64())
|
||||
initialCycle := true
|
||||
if err := stages.StageLoopStep(m.Ctx, m.Log, m.DB, m.Sync, highestSeenHeader, m.Notifications, initialCycle, m.UpdateHead, nil); err != nil {
|
||||
if err := stages.StageLoopStep(m.Ctx, m.DB, m.Sync, highestSeenHeader, m.Notifications, initialCycle, m.UpdateHead, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,6 @@ import (
|
||||
// StageLoop runs the continuous loop of staged sync
|
||||
func StageLoop(
|
||||
ctx context.Context,
|
||||
logger log.Logger,
|
||||
db kv.RwDB,
|
||||
sync *stagedsync.Sync,
|
||||
hd *headerdownload.HeaderDownload,
|
||||
@ -52,7 +51,7 @@ func StageLoop(
|
||||
|
||||
// Estimate the current top height seen from the peer
|
||||
height := hd.TopSeenHeight()
|
||||
if err := StageLoopStep(ctx, logger, db, sync, height, notifications, initialCycle, updateHead, nil); err != nil {
|
||||
if err := StageLoopStep(ctx, db, sync, height, notifications, initialCycle, updateHead, nil); err != nil {
|
||||
if errors.Is(err, common.ErrStopped) {
|
||||
return
|
||||
}
|
||||
@ -82,7 +81,6 @@ func StageLoop(
|
||||
|
||||
func StageLoopStep(
|
||||
ctx context.Context,
|
||||
logger log.Logger,
|
||||
db kv.RwDB,
|
||||
sync *stagedsync.Sync,
|
||||
highestSeenHeader uint64,
|
||||
|
Loading…
Reference in New Issue
Block a user