mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
Minor Refactor
This commit is contained in:
parent
dcb6cabb77
commit
beaf6da26d
5 changed files with 30 additions and 20 deletions
|
|
@ -54,8 +54,17 @@ func (c *ChainWatchCommand) Run(args []string) int {
|
|||
// if err == EOF if finished on the other side
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("message received")
|
||||
fmt.Println(msg)
|
||||
if msg.Type == "head" {
|
||||
fmt.Println("Block Added : ", msg.Newchain)
|
||||
} else if msg.Type == "fork" {
|
||||
fmt.Println("New Fork Block :", msg.Newchain)
|
||||
} else if msg.Type == "reorg" {
|
||||
fmt.Println("Reorg Detected")
|
||||
fmt.Println("Added :", msg.Newchain)
|
||||
fmt.Println("Removed :", msg.Oldchain)
|
||||
}
|
||||
|
||||
// fmt.Println(msg)
|
||||
}
|
||||
|
||||
return 0
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ func ConvertBlockToBlockStub(blocks []*types.Block) []*proto.BlockStub {
|
|||
}
|
||||
|
||||
func (s *Server) ChainWatch(req *proto.ChainWatchRequest, reply proto.Bor_ChainWatchServer) error {
|
||||
// 1. start the feed to the blcokchain events
|
||||
// 1. start the feed to the blockchain events
|
||||
// 2. for each event send a proto.ChainWatchResponse
|
||||
|
||||
chain2HeadChanSize := 10
|
||||
|
|
@ -136,7 +136,7 @@ func (s *Server) ChainWatch(req *proto.ChainWatchRequest, reply proto.Bor_ChainW
|
|||
|
||||
for {
|
||||
msg := <-chain2HeadCh
|
||||
fmt.Print(msg)
|
||||
|
||||
reply.Send(&proto.ChainWatchResponse{Type: msg.Type,
|
||||
Newchain: ConvertBlockToBlockStub(msg.NewChain),
|
||||
Oldchain: ConvertBlockToBlockStub(msg.OldChain),
|
||||
|
|
|
|||
|
|
@ -175,16 +175,15 @@ type BlockChain struct {
|
|||
// * nil: disable tx reindexer/deleter, but still index new blocks
|
||||
txLookupLimit uint64
|
||||
|
||||
hc *HeaderChain
|
||||
rmLogsFeed event.Feed
|
||||
chainFeed event.Feed
|
||||
chainSideFeed event.Feed
|
||||
chainHeadFeed event.Feed
|
||||
chain2HeadFeed event.Feed
|
||||
logsFeed event.Feed
|
||||
blockProcFeed event.Feed
|
||||
scope event.SubscriptionScope
|
||||
genesisBlock *types.Block
|
||||
hc *HeaderChain
|
||||
rmLogsFeed event.Feed
|
||||
chainFeed event.Feed
|
||||
chainSideFeed event.Feed
|
||||
chainHeadFeed event.Feed
|
||||
logsFeed event.Feed
|
||||
blockProcFeed event.Feed
|
||||
scope event.SubscriptionScope
|
||||
genesisBlock *types.Block
|
||||
|
||||
// This mutex synchronizes chain write operations.
|
||||
// Readers don't need to take it, they can just read the database.
|
||||
|
|
@ -218,6 +217,7 @@ type BlockChain struct {
|
|||
borReceiptsCache *lru.Cache // Cache for the most recent bor receipt receipts per block
|
||||
stateSyncData []*types.StateSyncData // State sync data
|
||||
stateSyncFeed event.Feed // State sync feed
|
||||
chain2HeadFeed event.Feed // Reorg/NewHead/Fork data feed
|
||||
}
|
||||
|
||||
// NewBlockChain returns a fully initialised block chain using information
|
||||
|
|
|
|||
|
|
@ -8,3 +8,10 @@ import (
|
|||
type StateSyncEvent struct {
|
||||
Data *types.StateSyncData
|
||||
}
|
||||
|
||||
// For tracking reorgs related information
|
||||
type Chain2HeadEvent struct {
|
||||
NewChain []*types.Block
|
||||
OldChain []*types.Block
|
||||
Type string
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,9 +41,3 @@ type ChainSideEvent struct {
|
|||
}
|
||||
|
||||
type ChainHeadEvent struct{ Block *types.Block }
|
||||
|
||||
type Chain2HeadEvent struct {
|
||||
NewChain []*types.Block
|
||||
OldChain []*types.Block
|
||||
Type string
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue