mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
Merge pull request #86 from maticnetwork/fix-deposit-subscribe
Fix deposit subscribe
This commit is contained in:
commit
05243eb7c4
6 changed files with 44 additions and 35 deletions
|
|
@ -655,6 +655,8 @@ func (c *Bor) Prepare(chain consensus.ChainReader, header *types.Header) error {
|
||||||
// Finalize implements consensus.Engine, ensuring no uncles are set, nor block
|
// Finalize implements consensus.Engine, ensuring no uncles are set, nor block
|
||||||
// rewards given.
|
// rewards given.
|
||||||
func (c *Bor) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header) {
|
func (c *Bor) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header) {
|
||||||
|
stateSyncData := []*types.StateData{}
|
||||||
|
var err error
|
||||||
headerNumber := header.Number.Uint64()
|
headerNumber := header.Number.Uint64()
|
||||||
if headerNumber%c.config.Sprint == 0 {
|
if headerNumber%c.config.Sprint == 0 {
|
||||||
cx := chainContext{Chain: chain, Bor: c}
|
cx := chainContext{Chain: chain, Bor: c}
|
||||||
|
|
@ -666,7 +668,7 @@ func (c *Bor) Finalize(chain consensus.ChainReader, header *types.Header, state
|
||||||
|
|
||||||
if !c.WithoutHeimdall {
|
if !c.WithoutHeimdall {
|
||||||
// commit statees
|
// commit statees
|
||||||
_, err := c.CommitStates(state, header, cx)
|
stateSyncData, err = c.CommitStates(state, header, cx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error while committing states", "error", err)
|
log.Error("Error while committing states", "error", err)
|
||||||
return
|
return
|
||||||
|
|
@ -677,6 +679,8 @@ func (c *Bor) Finalize(chain consensus.ChainReader, header *types.Header, state
|
||||||
// No block rewards in PoA, so the state remains as is and uncles are dropped
|
// No block rewards in PoA, so the state remains as is and uncles are dropped
|
||||||
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
|
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
|
||||||
header.UncleHash = types.CalcUncleHash(nil)
|
header.UncleHash = types.CalcUncleHash(nil)
|
||||||
|
bc := chain.(*core.BlockChain)
|
||||||
|
bc.SetStateSync(stateSyncData)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FinalizeAndAssemble implements consensus.Engine, ensuring no uncles are set,
|
// FinalizeAndAssemble implements consensus.Engine, ensuring no uncles are set,
|
||||||
|
|
@ -707,10 +711,11 @@ func (c *Bor) FinalizeAndAssemble(chain consensus.ChainReader, header *types.Hea
|
||||||
// No block rewards in PoA, so the state remains as is and uncles are dropped
|
// No block rewards in PoA, so the state remains as is and uncles are dropped
|
||||||
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
|
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
|
||||||
header.UncleHash = types.CalcUncleHash(nil)
|
header.UncleHash = types.CalcUncleHash(nil)
|
||||||
|
|
||||||
// Assemble block
|
// Assemble block
|
||||||
block := types.NewBlock(header, txs, nil, receipts)
|
block := types.NewBlock(header, txs, nil, receipts)
|
||||||
|
bc := chain.(*core.BlockChain)
|
||||||
block.SetStateSync(stateSyncData)
|
bc.SetStateSync(stateSyncData)
|
||||||
// return the final block for sealing
|
// return the final block for sealing
|
||||||
return block, nil
|
return block, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -180,6 +180,8 @@ type BlockChain struct {
|
||||||
txLookupCache *lru.Cache // Cache for the most recent transaction lookup data.
|
txLookupCache *lru.Cache // Cache for the most recent transaction lookup data.
|
||||||
futureBlocks *lru.Cache // future blocks are blocks added for later processing
|
futureBlocks *lru.Cache // future blocks are blocks added for later processing
|
||||||
|
|
||||||
|
stateSyncData []*types.StateData
|
||||||
|
|
||||||
quit chan struct{} // blockchain quit channel
|
quit chan struct{} // blockchain quit channel
|
||||||
wg sync.WaitGroup // chain processing wait group for shutting down
|
wg sync.WaitGroup // chain processing wait group for shutting down
|
||||||
running int32 // 0 if chain is running, 1 when stopped
|
running int32 // 0 if chain is running, 1 when stopped
|
||||||
|
|
@ -333,6 +335,11 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
|
||||||
return bc, nil
|
return bc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetStateSync set sync data in state_data
|
||||||
|
func (bc *BlockChain) SetStateSync(stateData []*types.StateData) {
|
||||||
|
bc.stateSyncData = stateData
|
||||||
|
}
|
||||||
|
|
||||||
// GetVMConfig returns the block chain VM config.
|
// GetVMConfig returns the block chain VM config.
|
||||||
func (bc *BlockChain) GetVMConfig() *vm.Config {
|
func (bc *BlockChain) GetVMConfig() *vm.Config {
|
||||||
return &bc.vmConfig
|
return &bc.vmConfig
|
||||||
|
|
@ -1541,10 +1548,9 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
|
||||||
// event here.
|
// event here.
|
||||||
if emitHeadEvent {
|
if emitHeadEvent {
|
||||||
bc.chainHeadFeed.Send(ChainHeadEvent{Block: block})
|
bc.chainHeadFeed.Send(ChainHeadEvent{Block: block})
|
||||||
}
|
for _, data := range bc.stateSyncData {
|
||||||
syncData := block.StateSyncData()
|
bc.stateSyncFeed.Send(StateSyncEvent{StateData: data})
|
||||||
for _, data := range syncData {
|
}
|
||||||
bc.stateSyncFeed.Send(StateSyncEvent{StateData: data})
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bc.chainSideFeed.Send(ChainSideEvent{Block: block})
|
bc.chainSideFeed.Send(ChainSideEvent{Block: block})
|
||||||
|
|
@ -1797,6 +1803,9 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, er
|
||||||
// Process block using the parent state as reference point
|
// Process block using the parent state as reference point
|
||||||
substart := time.Now()
|
substart := time.Now()
|
||||||
receipts, logs, usedGas, err := bc.processor.Process(block, statedb, bc.vmConfig)
|
receipts, logs, usedGas, err := bc.processor.Process(block, statedb, bc.vmConfig)
|
||||||
|
for _, data := range bc.stateSyncData {
|
||||||
|
bc.stateSyncFeed.Send(StateSyncEvent{StateData: data})
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
bc.reportBlock(block, receipts, err)
|
bc.reportBlock(block, receipts, err)
|
||||||
atomic.StoreUint32(&followupInterrupt, 1)
|
atomic.StoreUint32(&followupInterrupt, 1)
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,6 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
|
||||||
}
|
}
|
||||||
// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
|
// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
|
||||||
p.engine.Finalize(p.bc, header, statedb, block.Transactions(), block.Uncles())
|
p.engine.Finalize(p.bc, header, statedb, block.Transactions(), block.Uncles())
|
||||||
|
|
||||||
return receipts, allLogs, *usedGas, nil
|
return receipts, allLogs, *usedGas, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -156,10 +156,10 @@ type Body struct {
|
||||||
|
|
||||||
// Block represents an entire block in the Ethereum blockchain.
|
// Block represents an entire block in the Ethereum blockchain.
|
||||||
type Block struct {
|
type Block struct {
|
||||||
header *Header
|
header *Header
|
||||||
uncles []*Header
|
uncles []*Header
|
||||||
transactions Transactions
|
transactions Transactions
|
||||||
stateSyncData []*StateData
|
|
||||||
// caches
|
// caches
|
||||||
hash atomic.Value
|
hash atomic.Value
|
||||||
size atomic.Value
|
size atomic.Value
|
||||||
|
|
@ -266,11 +266,6 @@ func CopyHeader(h *Header) *Header {
|
||||||
return &cpy
|
return &cpy
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetStateSync set sync data in block
|
|
||||||
func (b *Block) SetStateSync(stateData []*StateData) {
|
|
||||||
b.stateSyncData = stateData
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecodeRLP decodes the Ethereum
|
// DecodeRLP decodes the Ethereum
|
||||||
func (b *Block) DecodeRLP(s *rlp.Stream) error {
|
func (b *Block) DecodeRLP(s *rlp.Stream) error {
|
||||||
var eb extblock
|
var eb extblock
|
||||||
|
|
@ -316,12 +311,11 @@ func (b *Block) Transaction(hash common.Hash) *Transaction {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Block) Number() *big.Int { return new(big.Int).Set(b.header.Number) }
|
func (b *Block) Number() *big.Int { return new(big.Int).Set(b.header.Number) }
|
||||||
func (b *Block) GasLimit() uint64 { return b.header.GasLimit }
|
func (b *Block) GasLimit() uint64 { return b.header.GasLimit }
|
||||||
func (b *Block) GasUsed() uint64 { return b.header.GasUsed }
|
func (b *Block) GasUsed() uint64 { return b.header.GasUsed }
|
||||||
func (b *Block) Difficulty() *big.Int { return new(big.Int).Set(b.header.Difficulty) }
|
func (b *Block) Difficulty() *big.Int { return new(big.Int).Set(b.header.Difficulty) }
|
||||||
func (b *Block) Time() uint64 { return b.header.Time }
|
func (b *Block) Time() uint64 { return b.header.Time }
|
||||||
func (b *Block) StateSyncData() []*StateData { return b.stateSyncData }
|
|
||||||
|
|
||||||
func (b *Block) NumberU64() uint64 { return b.header.Number.Uint64() }
|
func (b *Block) NumberU64() uint64 { return b.header.Number.Uint64() }
|
||||||
func (b *Block) MixDigest() common.Hash { return b.header.MixDigest }
|
func (b *Block) MixDigest() common.Hash { return b.header.MixDigest }
|
||||||
|
|
@ -378,10 +372,9 @@ func (b *Block) WithSeal(header *Header) *Block {
|
||||||
cpy := *header
|
cpy := *header
|
||||||
|
|
||||||
return &Block{
|
return &Block{
|
||||||
header: &cpy,
|
header: &cpy,
|
||||||
transactions: b.transactions,
|
transactions: b.transactions,
|
||||||
uncles: b.uncles,
|
uncles: b.uncles,
|
||||||
stateSyncData: b.stateSyncData,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
11
core/types/state_data.go
Normal file
11
core/types/state_data.go
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
package types
|
||||||
|
|
||||||
|
import "github.com/maticnetwork/bor/common"
|
||||||
|
|
||||||
|
// StateData represents state received from Ethereum Blockchain
|
||||||
|
type StateData struct {
|
||||||
|
Did uint64
|
||||||
|
Contract common.Address
|
||||||
|
Data string
|
||||||
|
TxHash common.Hash
|
||||||
|
}
|
||||||
|
|
@ -60,14 +60,6 @@ type txdata struct {
|
||||||
Hash *common.Hash `json:"hash" rlp:"-"`
|
Hash *common.Hash `json:"hash" rlp:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// State represents state received from Ethereum Blockchain
|
|
||||||
type StateData struct {
|
|
||||||
Did uint64
|
|
||||||
Contract common.Address
|
|
||||||
Data string
|
|
||||||
TxHash common.Hash
|
|
||||||
}
|
|
||||||
|
|
||||||
type txdataMarshaling struct {
|
type txdataMarshaling struct {
|
||||||
AccountNonce hexutil.Uint64
|
AccountNonce hexutil.Uint64
|
||||||
Price *hexutil.Big
|
Price *hexutil.Big
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue