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

multi: Add started and done reorg notifications. #1495

Merged
merged 1 commit into from
Oct 13, 2018

Conversation

dnldd
Copy link
Member

@dnldd dnldd commented Oct 13, 2018

This adds NTChainReorgStarted and NTChainReorgDone notifications to the blockmanager.

@dnldd
Copy link
Member Author

dnldd commented Oct 13, 2018

Sample simnet reorg output:

2018-10-13 01:11:23.165 [DBG] PEER: Adding deadline for command getdata for peer 127.0.0.1:55404
2018-10-13 01:11:23.165 [INF] CHAN: FORK: Block 1562e322fdd9014f82cd854be21141aaf9d671f32feb84f246ef2970f1a11a1b (height 33) forks the chain at height 32/block 051cd3f14d01110744c8d02ffa01cb445e9e77acd88a033fc8e4d0d4d46399a5, but does not cause a reorganize
2018-10-13 01:11:23.165 [DBG] CHAN: Accepted block 1562e322fdd9014f82cd854be21141aaf9d671f32feb84f246ef2970f1a11a1b
2018-10-13 01:11:23.165 [DBG] CHAN: Block 1562e322fdd9014f82cd854be21141aaf9d671f32feb84f246ef2970f1a11a1b (height 33) finished processing in 411.133µs
2018-10-13 01:11:23.165 [INF] BMGR: Processed 1 block in the last 3m8.16s (2 transactions, 0 tickets, 0 votes, 0 revocations, height 33, 2018-10-13 01:10:23 +0000 GMT)
2018-10-13 01:11:23.165 [DBG] PEER: Received block (hash 0d2071ca767a3f80b75e872d3a15d515ca5876099d03ece8fa516238db325049, ver 5, 1 tx, 2018-10-13 01:10:23 +0000 GMT) from 127.0.0.1:55404 (inbound)
2018-10-13 01:11:23.166 [INF] CHAN: REORGANIZE: Block 0d2071ca767a3f80b75e872d3a15d515ca5876099d03ece8fa516238db325049 is causing a reorganize.
2018-10-13 01:11:23.168 [DBG] CHAN: New best chain validation completed successfully, commencing with the reorganization.
2018-10-13 01:11:23.168 [INF] BMGR: Chain reorganization started.
2018-10-13 01:11:23.168 [DBG] TXMP: Accepted transaction c41f40b82e491ce3081fe929ebebd5ff98b5b682e376418dff47b23b75e58864 (pool size: 19)
2018-10-13 01:11:23.169 [DBG] TXMP: Accepted transaction 6d1be74e763e82ec1f856794e34412fcc4f69d2a508ecae8c19c1fae5b2fbfde (pool size: 20)
2018-10-13 01:11:23.169 [DBG] TXMP: Accepted transaction d0bc96fe1117d784310c7201a3a5a5159a5fca812d72f5f5f6a95c932f8b7342 (pool size: 21)
2018-10-13 01:11:23.169 [DBG] TXMP: Accepted transaction 6efade912b127e8fb58f2b9a69f33db797e83067a08fe493f04745eb2e07b8c0 (pool size: 22)
2018-10-13 01:11:23.169 [DBG] TXMP: Accepted transaction eab59bfcd80b84307d7b5302cdf84dd583393cb1b48fe7149fe34165d9154939 (pool size: 23)
2018-10-13 01:11:23.170 [DBG] RPCS: Received command <getcfilter> from [::1]:55397
2018-10-13 01:11:23.170 [INF] CHAN: REORGANIZE: Chain forks at 051cd3f14d01110744c8d02ffa01cb445e9e77acd88a033fc8e4d0d4d46399a5 (height 32)
2018-10-13 01:11:23.170 [INF] CHAN: REORGANIZE: Old best chain head was 0906ea2681a967eb9403ffd0b976a78d93f604d80a48d3d99b3c2223d2f69c02 (height 33)
2018-10-13 01:11:23.171 [INF] CHAN: REORGANIZE: New best chain head is 0d2071ca767a3f80b75e872d3a15d515ca5876099d03ece8fa516238db325049 (height 34)
2018-10-13 01:11:23.171 [INF] BMGR: Chain reorganization ended.
2018-10-13 01:11:23.171 [DBG] CHAN: Accepted block 0d2071ca767a3f80b75e872d3a15d515ca5876099d03ece8fa516238db325049
2018-10-13 01:11:23.171 [DBG] CHAN: Block 0d2071ca767a3f80b75e872d3a15d515ca5876099d03ece8fa516238db325049 (height 34) finished processing in 5.074942ms
2018-10-13 01:11:23.170 [DBG] RPCS: Found committed filter for 1562e322fdd9014f82cd854be21141aaf9d671f32feb84f246ef2970f1a11a1b
2018-10-13 01:11:23.171 [DBG] RPCS: Received command <getcfilter> from [::1]:55397
2018-10-13 01:11:23.171 [DBG] RPCS: Found committed filter for 0d2071ca767a3f80b75e872d3a15d515ca5876099d03ece8fa516238db325049
2018-10-13 01:11:26.164 [DBG] PEER: Received getminings from 127.0.0.1:55404 (inbound)
2018-10-13 01:11:26.166 [DBG] PEER: Sending getminings to 127.0.0.1:55404 (inbound)
2018-10-13 01:11:26.166 [DBG] PEER: Adding deadline for command getminings for peer 127.0.0.1:55404
2018-10-13 01:11:38.167 [DBG] PEER: Stall ticker rolling over for peer 127.0.0.1:55404 (inbound) on cmd miningstate (deadline for data: 2018-10-13 01:11:56.166977 +0000 GMT m=+221.234911386)

b.sendNotification(NTChainReorgStarted, &ChainReorgStarted{})
b.chainLock.Lock()

reorgDone := func() {
Copy link
Member

Choose a reason for hiding this comment

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

Can just defer this:

defer func() {
		// Send a notification announcing the end of the chain reorganization.
		b.chainLock.Unlock()
		b.sendNotification(NTChainReorgDone, nil)
		b.chainLock.Lock()
}()

@@ -1353,6 +1365,7 @@ func (b *BlockChain) reorganizeChain(detachNodes, attachNodes *list.List) error
parent = detachBlocks[i+1]
}
if n.parent.hash != *parent.Hash() {
reorgDone()
Copy link
Member

Choose a reason for hiding this comment

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

No point in doing this before panic, but can be removed anyway with suggested defer above.

blockmanager.go Outdated
@@ -1929,6 +1929,14 @@ func (b *blockManager) handleNotifyMsg(notification *blockchain.Notification) {
r.ntfnMgr.NotifyBlockDisconnected(block)
}

// Chain reorganization has commenced.
case blockchain.NTChainReorgStarted:
bmgrLog.Infof("Chain reorganization started.")
Copy link
Member

Choose a reason for hiding this comment

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

No reason to log this.

blockmanager.go Outdated

// Chain reorganization has concluded.
case blockchain.NTChainReorgDone:
bmgrLog.Infof("Chain reorganization ended.")
Copy link
Member

Choose a reason for hiding this comment

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

Nor this.

@@ -119,6 +127,12 @@ type ReorganizationNtfnsData struct {
NewHeight int64
}

// ChainReorgStarted signals the commencement of a chain reorganization.
type ChainReorgStarted struct{}
Copy link
Member

Choose a reason for hiding this comment

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

I don't see a reason for this type since it's empty anyway. Just use nil in the ntfn.

@@ -137,6 +151,8 @@ type TicketNotificationsData struct {
// - NTBlockAccepted: *BlockAcceptedNtfnsData
// - NTBlockConnected: []*dcrutil.Block of len 2
// - NTBlockDisconnected: []*dcrutil.Block of len 2
// - NTChainReorgStarted: *ChainReorgStarted
Copy link
Member

Choose a reason for hiding this comment

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

nil

@@ -137,6 +151,8 @@ type TicketNotificationsData struct {
// - NTBlockAccepted: *BlockAcceptedNtfnsData
// - NTBlockConnected: []*dcrutil.Block of len 2
// - NTBlockDisconnected: []*dcrutil.Block of len 2
// - NTChainReorgStarted: *ChainReorgStarted
// - NTChainReorgDone: *ChainReorgDone
Copy link
Member

Choose a reason for hiding this comment

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

nil

@@ -1331,6 +1331,18 @@ func (b *BlockChain) reorganizeChain(detachNodes, attachNodes *list.List) error
b.sendNotification(NTReorganization, reorgData)
b.chainLock.Lock()

// Send a notification announcing the start of the chain reorganization.
b.chainLock.Unlock()
b.sendNotification(NTChainReorgStarted, &ChainReorgStarted{})
Copy link
Member

Choose a reason for hiding this comment

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

See other comments. No need to create an empty heap object that has to be GC'd. Just use nil.

b.sendNotification(NTChainReorgStarted, nil)

type ChainReorgStarted struct{}

// ChainReorgDone signals the conclusion of a chain reorganization.
type ChainReorgDone struct{}
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

This adds NTChainReorgStarted and NTChainReorgDone notifications to
the blockmanager.
@davecgh davecgh merged commit 290e7e1 into decred:master Oct 13, 2018
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.

2 participants