mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-10-14 00:59:33 +00:00
(#DEV-14) Removed segwit from netwsync package
This commit is contained in:
parent
734abd749b
commit
82b87df13e
@ -226,15 +226,6 @@ func (sm *SyncManager) startSync() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Once the segwit soft-fork package has activated, we only
|
|
||||||
// want to sync from peers which are witness enabled to ensure
|
|
||||||
// that we fully validate all blockchain data.
|
|
||||||
segwitActive, err := sm.chain.IsDeploymentActive(chaincfg.DeploymentSegwit)
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("Unable to query for segwit soft-fork state: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
best := sm.chain.BestSnapshot()
|
best := sm.chain.BestSnapshot()
|
||||||
var bestPeer *peerpkg.Peer
|
var bestPeer *peerpkg.Peer
|
||||||
for peer, state := range sm.peerStates {
|
for peer, state := range sm.peerStates {
|
||||||
@ -242,11 +233,6 @@ func (sm *SyncManager) startSync() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if segwitActive && !peer.IsWitnessEnabled() {
|
|
||||||
log.Debugf("peer %v not witness enabled, skipping", peer)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove sync candidate peers that are no longer candidates due
|
// Remove sync candidate peers that are no longer candidates due
|
||||||
// to passing their latest known block. NOTE: The < is
|
// to passing their latest known block. NOTE: The < is
|
||||||
// intentional as opposed to <=. While technically the peer
|
// intentional as opposed to <=. While technically the peer
|
||||||
@ -334,16 +320,9 @@ func (sm *SyncManager) isSyncCandidate(peer *peerpkg.Peer) bool {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// The peer is not a candidate for sync if it's not a full
|
// The peer is not a candidate for sync if it's not a full
|
||||||
// node. Additionally, if the segwit soft-fork package has
|
// node.
|
||||||
// activated, then the peer must also be upgraded.
|
|
||||||
segwitActive, err := sm.chain.IsDeploymentActive(chaincfg.DeploymentSegwit)
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("Unable to query for segwit "+
|
|
||||||
"soft-fork state: %v", err)
|
|
||||||
}
|
|
||||||
nodeServices := peer.Services()
|
nodeServices := peer.Services()
|
||||||
if nodeServices&wire.SFNodeNetwork != wire.SFNodeNetwork ||
|
if nodeServices&wire.SFNodeNetwork != wire.SFNodeNetwork {
|
||||||
(segwitActive && !peer.IsWitnessEnabled()) {
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -746,13 +725,6 @@ func (sm *SyncManager) fetchHeaderBlocks() {
|
|||||||
sm.requestedBlocks[*node.hash] = struct{}{}
|
sm.requestedBlocks[*node.hash] = struct{}{}
|
||||||
syncPeerState.requestedBlocks[*node.hash] = struct{}{}
|
syncPeerState.requestedBlocks[*node.hash] = struct{}{}
|
||||||
|
|
||||||
// If we're fetching from a witness enabled peer
|
|
||||||
// post-fork, then ensure that we receive all the
|
|
||||||
// witness data in the blocks.
|
|
||||||
if sm.syncPeer.IsWitnessEnabled() {
|
|
||||||
iv.Type = wire.InvTypeWitnessBlock
|
|
||||||
}
|
|
||||||
|
|
||||||
gdmsg.AddInvVect(iv)
|
gdmsg.AddInvVect(iv)
|
||||||
numRequested++
|
numRequested++
|
||||||
}
|
}
|
||||||
@ -881,15 +853,11 @@ func (sm *SyncManager) handleHeadersMsg(hmsg *headersMsg) {
|
|||||||
// are in the memory pool (either the main pool or orphan pool).
|
// are in the memory pool (either the main pool or orphan pool).
|
||||||
func (sm *SyncManager) haveInventory(invVect *wire.InvVect) (bool, error) {
|
func (sm *SyncManager) haveInventory(invVect *wire.InvVect) (bool, error) {
|
||||||
switch invVect.Type {
|
switch invVect.Type {
|
||||||
case wire.InvTypeWitnessBlock:
|
|
||||||
fallthrough
|
|
||||||
case wire.InvTypeBlock:
|
case wire.InvTypeBlock:
|
||||||
// Ask chain if the block is known to it in any form (main
|
// Ask chain if the block is known to it in any form (main
|
||||||
// chain, side chain, or orphan).
|
// chain, side chain, or orphan).
|
||||||
return sm.chain.HaveBlock(&invVect.Hash)
|
return sm.chain.HaveBlock(&invVect.Hash)
|
||||||
|
|
||||||
case wire.InvTypeWitnessTx:
|
|
||||||
fallthrough
|
|
||||||
case wire.InvTypeTx:
|
case wire.InvTypeTx:
|
||||||
// Ask the transaction memory pool if the transaction is known
|
// Ask the transaction memory pool if the transaction is known
|
||||||
// to it in any form (main pool or orphan).
|
// to it in any form (main pool or orphan).
|
||||||
@ -979,8 +947,6 @@ func (sm *SyncManager) handleInvMsg(imsg *invMsg) {
|
|||||||
switch iv.Type {
|
switch iv.Type {
|
||||||
case wire.InvTypeBlock:
|
case wire.InvTypeBlock:
|
||||||
case wire.InvTypeTx:
|
case wire.InvTypeTx:
|
||||||
case wire.InvTypeWitnessBlock:
|
|
||||||
case wire.InvTypeWitnessTx:
|
|
||||||
default:
|
default:
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -1011,14 +977,6 @@ func (sm *SyncManager) handleInvMsg(imsg *invMsg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ignore invs block invs from non-witness enabled
|
|
||||||
// peers, as after segwit activation we only want to
|
|
||||||
// download from peers that can provide us full witness
|
|
||||||
// data for blocks.
|
|
||||||
if !peer.IsWitnessEnabled() && iv.Type == wire.InvTypeBlock {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add it to the request queue.
|
// Add it to the request queue.
|
||||||
state.requestQueue = append(state.requestQueue, iv)
|
state.requestQueue = append(state.requestQueue, iv)
|
||||||
continue
|
continue
|
||||||
@ -1076,8 +1034,6 @@ func (sm *SyncManager) handleInvMsg(imsg *invMsg) {
|
|||||||
requestQueue = requestQueue[1:]
|
requestQueue = requestQueue[1:]
|
||||||
|
|
||||||
switch iv.Type {
|
switch iv.Type {
|
||||||
case wire.InvTypeWitnessBlock:
|
|
||||||
fallthrough
|
|
||||||
case wire.InvTypeBlock:
|
case wire.InvTypeBlock:
|
||||||
// Request the block if there is not already a pending
|
// Request the block if there is not already a pending
|
||||||
// request.
|
// request.
|
||||||
@ -1086,16 +1042,10 @@ func (sm *SyncManager) handleInvMsg(imsg *invMsg) {
|
|||||||
sm.limitMap(sm.requestedBlocks, maxRequestedBlocks)
|
sm.limitMap(sm.requestedBlocks, maxRequestedBlocks)
|
||||||
state.requestedBlocks[iv.Hash] = struct{}{}
|
state.requestedBlocks[iv.Hash] = struct{}{}
|
||||||
|
|
||||||
if peer.IsWitnessEnabled() {
|
|
||||||
iv.Type = wire.InvTypeWitnessBlock
|
|
||||||
}
|
|
||||||
|
|
||||||
gdmsg.AddInvVect(iv)
|
gdmsg.AddInvVect(iv)
|
||||||
numRequested++
|
numRequested++
|
||||||
}
|
}
|
||||||
|
|
||||||
case wire.InvTypeWitnessTx:
|
|
||||||
fallthrough
|
|
||||||
case wire.InvTypeTx:
|
case wire.InvTypeTx:
|
||||||
// Request the transaction if there is not already a
|
// Request the transaction if there is not already a
|
||||||
// pending request.
|
// pending request.
|
||||||
@ -1104,12 +1054,6 @@ func (sm *SyncManager) handleInvMsg(imsg *invMsg) {
|
|||||||
sm.limitMap(sm.requestedTxns, maxRequestedTxns)
|
sm.limitMap(sm.requestedTxns, maxRequestedTxns)
|
||||||
state.requestedTxns[iv.Hash] = struct{}{}
|
state.requestedTxns[iv.Hash] = struct{}{}
|
||||||
|
|
||||||
// If the peer is capable, request the txn
|
|
||||||
// including all witness data.
|
|
||||||
if peer.IsWitnessEnabled() {
|
|
||||||
iv.Type = wire.InvTypeWitnessTx
|
|
||||||
}
|
|
||||||
|
|
||||||
gdmsg.AddInvVect(iv)
|
gdmsg.AddInvVect(iv)
|
||||||
numRequested++
|
numRequested++
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user