Skip to content
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

Merged
merged 2 commits into from
Nov 17, 2018

Conversation

CoderZhi
Copy link
Collaborator

  1. Delete channel
  2. Delete routine
  3. Implement Indexer and Server as subscribers

@CoderZhi CoderZhi requested a review from a team as a code owner November 10, 2018 00:16
@codecov
Copy link

codecov bot commented Nov 10, 2018

Codecov Report

Merging #307 into master will increase coverage by 0.05%.
The diff coverage is 12.82%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
server/itx/server.go 0% <0%> (ø) ⬆️
server/itx/subchain.go 5.88% <0%> (+1.33%) ⬆️
indexservice/indexer.go 0% <0%> (ø) ⬆️
indexservice/server.go 0% <0%> (ø) ⬆️
blockchain/blockchain.go 51.92% <83.33%> (-0.2%) ⬇️
network/pinger.go 12.5% <0%> (-37.5%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cba5ad0...4870d4a. Read the comment docs.

@@ -36,6 +36,7 @@ type ChainService struct {
explorer *explorer.Server
indexservice *indexservice.Server
protocols []Protocol
status bool
Copy link
Contributor

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) {

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

return nil
}

func (s *Server) startSubChainService(addr string, cs *chainservice.ChainService, blk *blockchain.Block) error {

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)
Copy link
Member

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

initializedSubChains: map[uint32]bool{},
}
if err := cs.Blockchain().AddSubscriber(&svr); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to Start()

Copy link
Contributor

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.

@@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this function then?

Msg("error when starting the sub-chain service")
}
}

},
s.cfg.System.StartSubChainInterval,
Copy link
Contributor

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

if err != nil {
return nil, nil, err
}
cs, ok := s.chainservices[chainID]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ineffectual assignment to cs

initializedSubChains: map[uint32]bool{},
}
if err := cs.Blockchain().AddSubscriber(&svr); err != nil {
Copy link
Contributor

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]
Copy link
Contributor

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
}

@CoderZhi CoderZhi merged commit 909a28c into iotexproject:master Nov 17, 2018
@CoderZhi CoderZhi deleted the stop_sub_chain_3 branch November 17, 2018 01:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants