-
Notifications
You must be signed in to change notification settings - Fork 328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
change block creation subscription implementation #307
Conversation
CoderZhi
commented
Nov 10, 2018
- Delete channel
- Delete routine
- Implement Indexer and Server as subscribers
898501e
to
de1f7b1
Compare
Codecov Report
@@ Coverage Diff @@
## master #307 +/- ##
=========================================
+ Coverage 62.74% 62.8% +0.05%
=========================================
Files 110 110
Lines 11109 11081 -28
=========================================
- Hits 6970 6959 -11
+ Misses 3170 3153 -17
Partials 969 969
Continue to review full report at Codecov.
|
chainservice/chainservice.go
Outdated
@@ -36,6 +36,7 @@ type ChainService struct { | |||
explorer *explorer.Server | |||
indexservice *indexservice.Server | |||
protocols []Protocol | |||
status bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit runningStatus
handler <- blk | ||
}(handler) | ||
for _, s := range bc.blocklistener { | ||
go func(bcs BlockCreationSubscriber, b *Block) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(*blockchain).emitToSubscribers$1
- b
is unused
server/itx/subchain.go
Outdated
return nil | ||
} | ||
|
||
func (s *Server) startSubChainService(addr string, cs *chainservice.ChainService, blk *blockchain.Block) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(*Server).startSubChainService
- blk
is unused
if err := bcs.HandleBlock(blk); err != nil { | ||
logger.Error().Err(err).Msg("Failed to handle new block") | ||
} | ||
}(s, blk) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to pass in 'blk'? as cibot commented above
server/itx/server.go
Outdated
initializedSubChains: map[uint32]bool{}, | ||
} | ||
if err := cs.Blockchain().AddSubscriber(&svr); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this to Start()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like the unsubscribe in the stop lifecycle event. Subscribe is better to be put into start lifecycle event.
server/itx/subchain.go
Outdated
@@ -16,100 +16,81 @@ import ( | |||
"github.com/iotexproject/iotex-core/action/protocols/multichain/mainchain" | |||
"github.com/iotexproject/iotex-core/address" | |||
"github.com/iotexproject/iotex-core/blockchain" | |||
"github.com/iotexproject/iotex-core/chainservice" | |||
"github.com/iotexproject/iotex-core/logger" | |||
"github.com/iotexproject/iotex-core/pkg/routine" | |||
) | |||
|
|||
func (s *Server) newSubChainStarter(protocol *mainchain.Protocol) *routine.RecurringTask { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete this function then?
server/itx/subchain.go
Outdated
Msg("error when starting the sub-chain service") | ||
} | ||
} | ||
|
||
}, | ||
s.cfg.System.StartSubChainInterval, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, you can kill the config
de1f7b1
to
fc690e2
Compare
if err != nil { | ||
return nil, nil, err | ||
} | ||
cs, ok := s.chainservices[chainID] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ineffectual assignment to cs
fc690e2
to
54482db
Compare
server/itx/server.go
Outdated
initializedSubChains: map[uint32]bool{}, | ||
} | ||
if err := cs.Blockchain().AddSubscriber(&svr); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like the unsubscribe in the stop lifecycle event. Subscribe is better to be put into start lifecycle event.
if err != nil { | ||
return nil, nil, err | ||
} | ||
cs, ok := s.chainservices[chainID] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if exist {
return cs, subChain, nil
}
54482db
to
527c889
Compare
527c889
to
4870d4a
Compare