mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
remove extra nevm mappings not needed
This commit is contained in:
parent
9230d12dad
commit
5c2e3d48ee
10 changed files with 48 additions and 124 deletions
|
|
@ -252,9 +252,6 @@ func (beacon *Beacon) verifyHeader(chain consensus.ChainHeaderReader, header, pa
|
||||||
if header.Time > uint64(unixNow+allowedFutureBlockTimeSeconds) {
|
if header.Time > uint64(unixNow+allowedFutureBlockTimeSeconds) {
|
||||||
return consensus.ErrFutureBlock
|
return consensus.ErrFutureBlock
|
||||||
}
|
}
|
||||||
if !chain.HasNEVMMapping(header.Hash()) {
|
|
||||||
return errors.New("block not found in NEVM mapping")
|
|
||||||
}
|
|
||||||
// Verify the block's difficulty to ensure it's the default constant
|
// Verify the block's difficulty to ensure it's the default constant
|
||||||
if !chain.Config().IsNexus(header.Number) {
|
if !chain.Config().IsNexus(header.Number) {
|
||||||
if header.Difficulty.Cmp(big.NewInt(1)) != 0 {
|
if header.Difficulty.Cmp(big.NewInt(1)) != 0 {
|
||||||
|
|
|
||||||
|
|
@ -45,9 +45,6 @@ type ChainHeaderReader interface {
|
||||||
// GetHeaderByHash retrieves a block header from the database by its hash.
|
// GetHeaderByHash retrieves a block header from the database by its hash.
|
||||||
GetHeaderByHash(hash common.Hash) *types.Header
|
GetHeaderByHash(hash common.Hash) *types.Header
|
||||||
|
|
||||||
// SYSCOIN check to see if an NEVM mapping exists for a specific block hash
|
|
||||||
HasNEVMMapping(hash common.Hash) bool
|
|
||||||
|
|
||||||
// GetTd retrieves the total difficulty from the database by hash and number.
|
// GetTd retrieves the total difficulty from the database by hash and number.
|
||||||
GetTd(hash common.Hash, number uint64) *big.Int
|
GetTd(hash common.Hash, number uint64) *big.Int
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -258,8 +258,6 @@ type BlockChain struct {
|
||||||
prefetcher Prefetcher
|
prefetcher Prefetcher
|
||||||
processor Processor // Block transaction processor interface
|
processor Processor // Block transaction processor interface
|
||||||
vmConfig vm.Config
|
vmConfig vm.Config
|
||||||
// SYSCOIN
|
|
||||||
NevmBlockConnect *types.NEVMBlockConnect
|
|
||||||
logger *tracing.Hooks
|
logger *tracing.Hooks
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1108,12 +1106,6 @@ func (bc *BlockChain) stopWithoutSaving() {
|
||||||
// Stop stops the blockchain service. If any imports are currently in progress
|
// Stop stops the blockchain service. If any imports are currently in progress
|
||||||
// it will abort them using the procInterrupt.
|
// it will abort them using the procInterrupt.
|
||||||
func (bc *BlockChain) Stop() {
|
func (bc *BlockChain) Stop() {
|
||||||
// SYSCOIN we set canonical chain if we are stopping or we have synced
|
|
||||||
if bc.NevmBlockConnect != nil {
|
|
||||||
if _, err := bc.SetCanonical(bc.NevmBlockConnect.Block); err != nil {
|
|
||||||
log.Error("Failed setting canonical chain from NEVM block connect", "err", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bc.stopWithoutSaving()
|
bc.stopWithoutSaving()
|
||||||
|
|
||||||
// Ensure that the entirety of the state snapshot is journaled to disk.
|
// Ensure that the entirety of the state snapshot is journaled to disk.
|
||||||
|
|
@ -1475,7 +1467,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
|
||||||
rawdb.WriteReceipts(blockBatch, block.Hash(), block.NumberU64(), receipts)
|
rawdb.WriteReceipts(blockBatch, block.Hash(), block.NumberU64(), receipts)
|
||||||
rawdb.WritePreimages(blockBatch, statedb.Preimages())
|
rawdb.WritePreimages(blockBatch, statedb.Preimages())
|
||||||
// SYSCOIN
|
// SYSCOIN
|
||||||
nevmBlockConnect := bc.NevmBlockConnect
|
nevmBlockConnect := block.NevmBlockConnect
|
||||||
if nevmBlockConnect != nil {
|
if nevmBlockConnect != nil {
|
||||||
// Update the NEVM address mappings based on the block's diff
|
// Update the NEVM address mappings based on the block's diff
|
||||||
hasDiff := nevmBlockConnect.HasDiff()
|
hasDiff := nevmBlockConnect.HasDiff()
|
||||||
|
|
@ -1496,9 +1488,10 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
|
||||||
bc.WriteNEVMAddressMapping(blockBatch, mapping)
|
bc.WriteNEVMAddressMapping(blockBatch, mapping)
|
||||||
}
|
}
|
||||||
proposedBlockNumber := nevmBlockConnect.Block.NumberU64()
|
proposedBlockNumber := nevmBlockConnect.Block.NumberU64()
|
||||||
bc.WriteNEVMMapping(blockBatch, nevmBlockConnect.Block.Hash())
|
|
||||||
bc.WriteDataHashes(blockBatch, proposedBlockNumber, nevmBlockConnect.VersionHashes)
|
bc.WriteDataHashes(blockBatch, proposedBlockNumber, nevmBlockConnect.VersionHashes)
|
||||||
bc.WriteSYSHash(blockBatch, nevmBlockConnect.Sysblockhash, proposedBlockNumber)
|
bc.WriteSYSHash(blockBatch, nevmBlockConnect.Sysblockhash, proposedBlockNumber)
|
||||||
|
} else if bc.GetChainConfig().SyscoinBlock != nil {
|
||||||
|
return errors.New("No SYS block connect provided")
|
||||||
}
|
}
|
||||||
if err := blockBatch.Write(); err != nil {
|
if err := blockBatch.Write(); err != nil {
|
||||||
log.Crit("Failed to write block into disk", "err", err)
|
log.Crit("Failed to write block into disk", "err", err)
|
||||||
|
|
@ -1633,7 +1626,6 @@ func (bc *BlockChain) InsertChain(chain types.Blocks) (int, error) {
|
||||||
return 0, errChainStopped
|
return 0, errChainStopped
|
||||||
}
|
}
|
||||||
defer bc.chainmu.Unlock()
|
defer bc.chainmu.Unlock()
|
||||||
|
|
||||||
_, n, err := bc.insertChain(chain, true, false) // No witness collection for mass inserts (would get super large)
|
_, n, err := bc.insertChain(chain, true, false) // No witness collection for mass inserts (would get super large)
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -476,18 +476,3 @@ func (bc *BlockChain) DeleteSYSHash(db ethdb.KeyValueWriter, n uint64) {
|
||||||
bc.hc.DeleteSYSHash(db, n)
|
bc.hc.DeleteSYSHash(db, n)
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasNEVMMapping checks if a NEVM block is present in the database or not, caching
|
|
||||||
// it if present.
|
|
||||||
func (bc *BlockChain) HasNEVMMapping(hash common.Hash) bool {
|
|
||||||
if(bc.NevmBlockConnect != nil) {
|
|
||||||
return (bc.NevmBlockConnect.Block.Hash() == hash)
|
|
||||||
}
|
|
||||||
return bc.hc.HasNEVMMapping(hash)
|
|
||||||
}
|
|
||||||
func (bc *BlockChain) DeleteNEVMMapping(db ethdb.KeyValueWriter, hash common.Hash) {
|
|
||||||
bc.hc.DeleteNEVMMapping(db, hash)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (bc *BlockChain) WriteNEVMMapping(db ethdb.KeyValueWriter, hash common.Hash) {
|
|
||||||
bc.hc.WriteNEVMMapping(db, hash)
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -696,7 +696,6 @@ func (cm *chainMaker) GetTd(hash common.Hash, number uint64) *big.Int {
|
||||||
return nil // not supported
|
return nil // not supported
|
||||||
}
|
}
|
||||||
// SYSCOIN
|
// SYSCOIN
|
||||||
func (cm *chainMaker) HasNEVMMapping(hash common.Hash) bool { return false }
|
|
||||||
func (cm *chainMaker) ReadSYSHash(uint64) []byte {
|
func (cm *chainMaker) ReadSYSHash(uint64) []byte {
|
||||||
return []byte{}
|
return []byte{}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -579,24 +579,6 @@ func (hc *HeaderChain) DeleteSYSHash(db ethdb.KeyValueWriter, n uint64) {
|
||||||
rawdb.DeleteSYSHash(db, n)
|
rawdb.DeleteSYSHash(db, n)
|
||||||
hc.SYSHashCache.Remove(n)
|
hc.SYSHashCache.Remove(n)
|
||||||
}
|
}
|
||||||
func (hc *HeaderChain) HasNEVMMapping(hash common.Hash) bool {
|
|
||||||
if hc.NEVMCache.Contains(hash) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
hasMapping := rawdb.HasNEVMMapping(hc.chainDb, hash)
|
|
||||||
if hasMapping {
|
|
||||||
hc.NEVMCache.Add(hash, []byte{0})
|
|
||||||
}
|
|
||||||
return hasMapping
|
|
||||||
}
|
|
||||||
func (hc *HeaderChain) DeleteNEVMMapping(db ethdb.KeyValueWriter, hash common.Hash) {
|
|
||||||
rawdb.DeleteNEVMMapping(db, hash)
|
|
||||||
hc.NEVMCache.Remove(hash)
|
|
||||||
}
|
|
||||||
func (hc *HeaderChain) WriteNEVMMapping(db ethdb.KeyValueWriter, hash common.Hash) {
|
|
||||||
rawdb.WriteNEVMMapping(db, hash)
|
|
||||||
hc.NEVMCache.Add(hash, []byte{0})
|
|
||||||
}
|
|
||||||
|
|
||||||
// CurrentHeader retrieves the current head header of the canonical chain. The
|
// CurrentHeader retrieves the current head header of the canonical chain. The
|
||||||
// header is retrieved from the HeaderChain's internal cache.
|
// header is retrieved from the HeaderChain's internal cache.
|
||||||
|
|
|
||||||
|
|
@ -896,24 +896,6 @@ func ReadDataHash(db ethdb.Reader, hash common.Hash) []byte {
|
||||||
}
|
}
|
||||||
return hash.Bytes()
|
return hash.Bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
// SYSCOIN HasNEVMMapping verifies the existence of a NEVM block corresponding to the hash.
|
|
||||||
func HasNEVMMapping(db ethdb.Reader, hash common.Hash) bool {
|
|
||||||
if has, err := db.Has(nevmToSysKey(hash)); !has || err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
func WriteNEVMMapping(db ethdb.KeyValueWriter, hash common.Hash) {
|
|
||||||
if err := db.Put(nevmToSysKey(hash), []byte{0}); err != nil {
|
|
||||||
log.Crit("Failed to store nevmToSysKey", "err", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
func DeleteNEVMMapping(db ethdb.KeyValueWriter, hash common.Hash) {
|
|
||||||
if err := db.Delete(nevmToSysKey(hash)); err != nil {
|
|
||||||
log.Crit("Failed to delete nevmToSysKey", "err", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// DeleteBlock removes all block data associated with a hash.
|
// DeleteBlock removes all block data associated with a hash.
|
||||||
func DeleteBlock(db ethdb.KeyValueWriter, hash common.Hash, number uint64) {
|
func DeleteBlock(db ethdb.KeyValueWriter, hash common.Hash, number uint64) {
|
||||||
DeleteReceipts(db, hash, number)
|
DeleteReceipts(db, hash, number)
|
||||||
|
|
|
||||||
|
|
@ -230,6 +230,8 @@ type Block struct {
|
||||||
// inter-peer block relay.
|
// inter-peer block relay.
|
||||||
ReceivedAt time.Time
|
ReceivedAt time.Time
|
||||||
ReceivedFrom interface{}
|
ReceivedFrom interface{}
|
||||||
|
// SYSCOIN
|
||||||
|
NevmBlockConnect *NEVMBlockConnect
|
||||||
}
|
}
|
||||||
|
|
||||||
// "external" block encoding. used for eth protocol, etc.
|
// "external" block encoding. used for eth protocol, etc.
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,8 @@ func newCancunInstructionSet() JumpTable {
|
||||||
}
|
}
|
||||||
|
|
||||||
func newShanghaiInstructionSet() JumpTable {
|
func newShanghaiInstructionSet() JumpTable {
|
||||||
instructionSet := newMergeInstructionSet()
|
// SYSCOIN
|
||||||
|
instructionSet := newLondonInstructionSet()
|
||||||
enable3855(&instructionSet) // PUSH0 instruction
|
enable3855(&instructionSet) // PUSH0 instruction
|
||||||
enable3860(&instructionSet) // Limit and meter initcode
|
enable3860(&instructionSet) // Limit and meter initcode
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -295,67 +295,55 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
|
||||||
defer eth.wgNEVM.Done()
|
defer eth.wgNEVM.Done()
|
||||||
return eth.miner.GenerateWorkSyscoin(eth.blockchain.CurrentBlock().Hash(), eth.config.Miner.PendingFeeRecipient, crypto.Keccak256Hash([]byte{byte(123)}))
|
return eth.miner.GenerateWorkSyscoin(eth.blockchain.CurrentBlock().Hash(), eth.config.Miner.PendingFeeRecipient, crypto.Keccak256Hash([]byte{byte(123)}))
|
||||||
}
|
}
|
||||||
addBlock := func(nevmBlockConnect *types.NEVMBlockConnect, eth *Ethereum) error {
|
var (
|
||||||
if nevmBlockConnect == nil {
|
batchSize = 100 // Number of blocks to batch before processing
|
||||||
|
blockConnectBuffer = make([]*types.NEVMBlockConnect, 0, batchSize)
|
||||||
|
)
|
||||||
|
|
||||||
|
addBlock := func(nevmBlockConnectIn *types.NEVMBlockConnect, eth *Ethereum) error {
|
||||||
|
if nevmBlockConnectIn == nil || nevmBlockConnectIn.Block == nil {
|
||||||
return errors.New("addBlock: Empty block")
|
return errors.New("addBlock: Empty block")
|
||||||
}
|
}
|
||||||
proposedBlockNumber := nevmBlockConnect.Block.NumberU64()
|
|
||||||
proposedBlockHash := nevmBlockConnect.Block.Hash()
|
// Special case where miner process includes validating block in pre-packaging stage on SYS node
|
||||||
proposedBlockParentHash := nevmBlockConnect.Block.ParentHash()
|
sysBlockHash := common.BytesToHash([]byte(nevmBlockConnectIn.Sysblockhash))
|
||||||
currentHash := common.Hash{}
|
|
||||||
currentNumber := uint64(0)
|
|
||||||
if nevmBlockConnect.Block == nil {
|
|
||||||
return errors.New("addBlock: empty block")
|
|
||||||
}
|
|
||||||
// because we set canonical head only after sync we can check for continuity via saved block connects
|
|
||||||
if eth.blockchain.NevmBlockConnect != nil {
|
|
||||||
currentBlock := eth.blockchain.NevmBlockConnect.Block
|
|
||||||
if currentBlock == nil {
|
|
||||||
return errors.New("addBlock: Current block is nil")
|
|
||||||
}
|
|
||||||
currentNumber = currentBlock.NumberU64()
|
|
||||||
currentHash = currentBlock.Hash()
|
|
||||||
} else {
|
|
||||||
currentBlock := eth.blockchain.CurrentBlock()
|
|
||||||
if currentBlock == nil {
|
|
||||||
return errors.New("addBlock: Current block is nil")
|
|
||||||
}
|
|
||||||
currentNumber = currentBlock.Number.Uint64()
|
|
||||||
currentHash = currentBlock.Hash()
|
|
||||||
}
|
|
||||||
if (proposedBlockNumber != (currentNumber + 1)) || (proposedBlockParentHash != currentHash) {
|
|
||||||
log.Error("Non contiguous block insert", "number", proposedBlockNumber, "hash", proposedBlockHash,
|
|
||||||
"parent", proposedBlockParentHash, "prevnumber", currentNumber, "prevhash", currentHash)
|
|
||||||
return errors.New("addBlock: Non contiguous block insert")
|
|
||||||
}
|
|
||||||
eth.blockchain.NevmBlockConnect = nevmBlockConnect
|
|
||||||
// special case where miner process includes validating block in pre-packaging stage on SYS node
|
|
||||||
// the validation of this hash is done in ConnectNEVMCommitment() in Syscoin using fJustCheck
|
|
||||||
sysBlockHash := common.BytesToHash([]byte(nevmBlockConnect.Sysblockhash))
|
|
||||||
if sysBlockHash == (common.Hash{}) {
|
if sysBlockHash == (common.Hash{}) {
|
||||||
err := eth.engine.VerifyHeader(eth.blockchain, nevmBlockConnect.Block.Header())
|
if err := eth.engine.VerifyHeader(eth.blockchain, nevmBlockConnectIn.Block.Header()); err != nil {
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err := eth.blockchain.InsertBlockWithoutSetHead(nevmBlockConnect.Block, false); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if eth.handler.peers.closed {
|
|
||||||
eth.lock.Lock()
|
|
||||||
eth.timeLastBlock = time.Now().Unix()
|
|
||||||
eth.lock.Unlock()
|
|
||||||
if (nevmBlockConnect.Block.NumberU64() % 100) == 0 {
|
|
||||||
if _, err := eth.blockchain.SetCanonical(nevmBlockConnect.Block); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if _, err := eth.blockchain.SetCanonical(nevmBlockConnect.Block); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add block to the buffer
|
||||||
|
blockConnectBuffer = append(blockConnectBuffer, nevmBlockConnectIn)
|
||||||
|
// Check if we should process the buffer (batch size reached or sync finished)
|
||||||
|
if eth.handler.peers.closed && len(blockConnectBuffer) < batchSize {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process the buffer
|
||||||
|
batch := blockConnectBuffer
|
||||||
|
blockConnectBuffer = make([]*types.NEVMBlockConnect, 0, batchSize) // Clear the buffer for next batch
|
||||||
|
|
||||||
|
// Prepare the blocks for insertion
|
||||||
|
blockBuffer := make([]*types.Block, 0, len(batch))
|
||||||
|
for _, nevmBlockConnect := range batch {
|
||||||
|
nevmBlockConnect.Block.NevmBlockConnect = nevmBlockConnect
|
||||||
|
blockBuffer = append(blockBuffer, nevmBlockConnect.Block)
|
||||||
|
}
|
||||||
|
// Insert the batch of blocks into the blockchain
|
||||||
|
if _, err := eth.blockchain.InsertChain(blockBuffer); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the last block time
|
||||||
|
eth.lock.Lock()
|
||||||
|
eth.timeLastBlock = time.Now().Unix()
|
||||||
|
eth.lock.Unlock()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// start networking sync once we start inserting chain meaning we are likely finished with IBD
|
// start networking sync once we start inserting chain meaning we are likely finished with IBD
|
||||||
go func(eth *Ethereum) {
|
go func(eth *Ethereum) {
|
||||||
sub := eth.eventMux.Subscribe(downloader.StartNetworkEvent{})
|
sub := eth.eventMux.Subscribe(downloader.StartNetworkEvent{})
|
||||||
|
|
@ -431,7 +419,6 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
|
||||||
eth.blockchain.WriteNEVMAddressMapping(batch, mapping)
|
eth.blockchain.WriteNEVMAddressMapping(batch, mapping)
|
||||||
}
|
}
|
||||||
|
|
||||||
eth.blockchain.DeleteNEVMMapping(batch, current.Hash())
|
|
||||||
eth.blockchain.DeleteSYSHash(batch, currentNumber)
|
eth.blockchain.DeleteSYSHash(batch, currentNumber)
|
||||||
eth.blockchain.DeleteDataHashes(batch, currentNumber)
|
eth.blockchain.DeleteDataHashes(batch, currentNumber)
|
||||||
if err := batch.Write(); err != nil {
|
if err := batch.Write(); err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue