Minor Refactor

This commit is contained in:
Shivam Sharma 2021-12-03 17:28:53 +05:30
parent dcb6cabb77
commit beaf6da26d
5 changed files with 30 additions and 20 deletions

View file

@ -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

View file

@ -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),

View file

@ -180,7 +180,6 @@ type BlockChain struct {
chainFeed event.Feed
chainSideFeed event.Feed
chainHeadFeed event.Feed
chain2HeadFeed event.Feed
logsFeed event.Feed
blockProcFeed event.Feed
scope event.SubscriptionScope
@ -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

View file

@ -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
}

View file

@ -41,9 +41,3 @@ type ChainSideEvent struct {
}
type ChainHeadEvent struct{ Block *types.Block }
type Chain2HeadEvent struct {
NewChain []*types.Block
OldChain []*types.Block
Type string
}