@@ -8,6 +8,7 @@ package blockchain
8
8
import (
9
9
"container/list"
10
10
"fmt"
11
+ "github.com/libp2p/go-libp2p/core/peer"
11
12
"time"
12
13
13
14
"github.com/Qitmeer/qng/common/hash"
@@ -36,12 +37,12 @@ import (
36
37
//
37
38
// This function is safe for concurrent access.
38
39
// return IsOrphan,error
39
- func (b * BlockChain ) ProcessBlock (block * types.SerializedBlock , flags BehaviorFlags ) (meerdag.IBlock , bool , error ) {
40
+ func (b * BlockChain ) ProcessBlock (block * types.SerializedBlock , flags BehaviorFlags , source * peer. ID ) (meerdag.IBlock , bool , error ) {
40
41
if b .IsShutdown () {
41
42
return nil , false , fmt .Errorf ("block chain is shutdown" )
42
43
}
43
44
block .Reset ()
44
- msg := processMsg {block : block , flags : flags , result : make (chan * processResult )}
45
+ msg := processMsg {block : block , flags : flags , result : make (chan * processResult ), source : source }
45
46
b .msgChan <- & msg
46
47
result := <- msg .result
47
48
return result .block , result .isOrphan , result .err
54
55
select {
55
56
case msg := <- b .msgChan :
56
57
start := time .Now ()
57
- ib , isOrphan , err := b .processBlock (msg .block , msg .flags )
58
+ ib , isOrphan , err := b .processBlock (msg .block , msg .flags , msg . source )
58
59
blockProcessTimer .Update (time .Since (start ))
59
60
msg .result <- & processResult {isOrphan : isOrphan , err : err , block : ib }
60
61
case <- b .quit :
@@ -75,14 +76,14 @@ cleanup:
75
76
log .Trace ("BlockChain handler done" )
76
77
}
77
78
78
- func (b * BlockChain ) processBlock (block * types.SerializedBlock , flags BehaviorFlags ) (meerdag.IBlock , bool , error ) {
79
+ func (b * BlockChain ) processBlock (block * types.SerializedBlock , flags BehaviorFlags , source * peer. ID ) (meerdag.IBlock , bool , error ) {
79
80
isorphan , err := b .preProcessBlock (block , flags )
80
81
if err != nil || isorphan {
81
82
return nil , isorphan , err
82
83
}
83
84
// The block has passed all context independent checks and appears sane
84
85
// enough to potentially accept it into the block chain.
85
- ib , err := b .maybeAcceptBlock (block , flags )
86
+ ib , err := b .maybeAcceptBlock (block , flags , source )
86
87
if err != nil {
87
88
return nil , false , err
88
89
}
@@ -193,7 +194,7 @@ func (b *BlockChain) preProcessBlock(block *types.SerializedBlock, flags Behavio
193
194
// their documentation for how the flags modify their behavior.
194
195
//
195
196
// This function MUST be called with the chain state lock held (for writes).
196
- func (b * BlockChain ) maybeAcceptBlock (block * types.SerializedBlock , flags BehaviorFlags ) (meerdag.IBlock , error ) {
197
+ func (b * BlockChain ) maybeAcceptBlock (block * types.SerializedBlock , flags BehaviorFlags , source * peer. ID ) (meerdag.IBlock , error ) {
197
198
if onEnd := l .LogAndMeasureExecutionTime (log , "BlockChain.maybeAcceptBlock" ); onEnd != nil {
198
199
defer onEnd ()
199
200
}
@@ -293,6 +294,7 @@ func (b *BlockChain) maybeAcceptBlock(block *types.SerializedBlock, flags Behavi
293
294
Block : block ,
294
295
Flags : flags ,
295
296
Height : uint64 (ib .GetHeight ()),
297
+ Source : source ,
296
298
})
297
299
if b .Acct != nil {
298
300
err = b .Acct .Commit ()
@@ -304,7 +306,7 @@ func (b *BlockChain) maybeAcceptBlock(block *types.SerializedBlock, flags Behavi
304
306
}
305
307
306
308
func (b * BlockChain ) FastAcceptBlock (block * types.SerializedBlock , flags BehaviorFlags ) (meerdag.IBlock , error ) {
307
- return b .maybeAcceptBlock (block , flags )
309
+ return b .maybeAcceptBlock (block , flags , nil )
308
310
}
309
311
310
312
// connectBestChain handles connecting the passed block to the chain while
@@ -788,6 +790,7 @@ type processMsg struct {
788
790
block * types.SerializedBlock
789
791
flags BehaviorFlags
790
792
result chan * processResult
793
+ source * peer.ID
791
794
}
792
795
793
796
type processResult struct {
0 commit comments