Skip to content

Commit 2a6516f

Browse files
committed
Behave as a non-witness node when start time is far away
1 parent 3483e5c commit 2a6516f

File tree

4 files changed

+34
-11
lines changed

4 files changed

+34
-11
lines changed

src/chainparams.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ class CMainParams : public CChainParams {
9494

9595
// Deployment of SegWit (BIP141 and BIP143)
9696
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].bit = 1;
97-
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = 2000000000; // Far in the future
98-
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 2100000000;
97+
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = 0;
98+
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 0; // Never / undefined
9999

100100
/**
101101
* The message start string is designed to be unlikely to occur in normal data.

src/init.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,15 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
13841384
}
13851385
}
13861386

1387+
if (Params().GetConsensus().vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout != 0) {
1388+
// Only advertize witness capabilities if they have a reasonable start time.
1389+
// This allows us to have the code merged without a defined softfork, by setting its
1390+
// end time to 0.
1391+
// Note that setting NODE_WITNESS is never required: the only downside from not
1392+
// doing so is that after activation, no upgraded nodes will fetch from you.
1393+
nLocalServices |= NODE_WITNESS;
1394+
}
1395+
13871396
// ********************************************************* Step 10: import blocks
13881397

13891398
if (mapArgs.count("-blocknotify"))

src/main.cpp

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3134,7 +3134,10 @@ bool ReceivedBlockTransactions(const CBlock &block, CValidationState& state, CBl
31343134
pindexNew->nFile = pos.nFile;
31353135
pindexNew->nDataPos = pos.nPos;
31363136
pindexNew->nUndoPos = 0;
3137-
pindexNew->nStatus |= BLOCK_HAVE_DATA | BLOCK_OPT_WITNESS;
3137+
pindexNew->nStatus |= BLOCK_HAVE_DATA;
3138+
if (IsWitnessEnabled(pindexNew->pprev, Params().GetConsensus())) {
3139+
pindexNew->nStatus |= BLOCK_OPT_WITNESS;
3140+
}
31383141
pindexNew->RaiseValidity(BLOCK_VALID_TRANSACTIONS);
31393142
setDirtyBlockIndex.insert(pindexNew);
31403143

@@ -4752,6 +4755,14 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
47524755
}
47534756
}
47544757

4758+
uint32_t GetFetchFlags(CNode* pfrom, CBlockIndex* pprev, const Consensus::Params& chainparams) {
4759+
uint32_t nFetchFlags = 0;
4760+
if (IsWitnessEnabled(pprev, chainparams) && State(pfrom->GetId())->fHaveWitness) {
4761+
nFetchFlags |= MSG_WITNESS_FLAG;
4762+
}
4763+
return nFetchFlags;
4764+
}
4765+
47554766
bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, int64_t nTimeReceived, const CChainParams& chainparams)
47564767
{
47574768
RandAddSeedPerfmon();
@@ -5034,20 +5045,23 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
50345045

50355046
LOCK(cs_main);
50365047

5048+
uint32_t nFetchFlags = GetFetchFlags(pfrom, chainActive.Tip(), chainparams.GetConsensus());
5049+
50375050
std::vector<CInv> vToFetch;
50385051

50395052
for (unsigned int nInv = 0; nInv < vInv.size(); nInv++)
50405053
{
50415054
CInv &inv = vInv[nInv];
5055+
inv.type |= nFetchFlags;
50425056

50435057
boost::this_thread::interruption_point();
50445058
pfrom->AddInventoryKnown(inv);
50455059

50465060
bool fAlreadyHave = AlreadyHave(inv);
50475061
LogPrint("net", "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom->id);
50485062

5049-
if (inv.type == MSG_TX && State(pfrom->GetId())->fHaveWitness) {
5050-
inv.type = MSG_WITNESS_TX;
5063+
if (inv.type == MSG_TX) {
5064+
inv.type |= nFetchFlags;
50515065
}
50525066

50535067
if (inv.type == MSG_BLOCK) {
@@ -5066,9 +5080,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
50665080
if (CanDirectFetch(chainparams.GetConsensus()) &&
50675081
nodestate->nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER &&
50685082
(!IsWitnessEnabled(chainActive.Tip(), chainparams.GetConsensus()) || State(pfrom->GetId())->fHaveWitness)) {
5069-
if (State(pfrom->GetId())->fHaveWitness) {
5070-
inv.type = MSG_WITNESS_BLOCK;
5071-
}
5083+
inv.type |= nFetchFlags;
50725084
vToFetch.push_back(inv);
50735085
// Mark block as in flight already, even though the actual "getdata" message only goes out
50745086
// later (within the same cs_main lock, though).
@@ -5442,7 +5454,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
54425454
// Can't download any more from this peer
54435455
break;
54445456
}
5445-
vGetData.push_back(CInv(State(pfrom->GetId())->fHaveWitness ? MSG_WITNESS_BLOCK : MSG_BLOCK, pindex->GetBlockHash()));
5457+
uint32_t nFetchFlags = GetFetchFlags(pfrom, pindex->pprev, chainparams.GetConsensus());
5458+
vGetData.push_back(CInv(MSG_BLOCK | nFetchFlags, pindex->GetBlockHash()));
54465459
MarkBlockAsInFlight(pfrom->GetId(), pindex->GetBlockHash(), chainparams.GetConsensus(), pindex);
54475460
LogPrint("net", "Requesting block %s from peer=%d\n",
54485461
pindex->GetBlockHash().ToString(), pfrom->id);
@@ -6156,7 +6169,8 @@ bool SendMessages(CNode* pto)
61566169
FindNextBlocksToDownload(pto->GetId(), MAX_BLOCKS_IN_TRANSIT_PER_PEER - state.nBlocksInFlight, vToDownload, staller);
61576170
BOOST_FOREACH(CBlockIndex *pindex, vToDownload) {
61586171
if (State(pto->GetId())->fHaveWitness || !IsWitnessEnabled(pindex->pprev, consensusParams)) {
6159-
vGetData.push_back(CInv(State(pto->GetId())->fHaveWitness ? MSG_WITNESS_BLOCK : MSG_BLOCK, pindex->GetBlockHash()));
6172+
uint32_t nFetchFlags = GetFetchFlags(pto, pindex->pprev, consensusParams);
6173+
vGetData.push_back(CInv(MSG_BLOCK | nFetchFlags, pindex->GetBlockHash()));
61606174
MarkBlockAsInFlight(pto->GetId(), pindex->GetBlockHash(), consensusParams, pindex);
61616175
LogPrint("net", "Requesting block %s (%d) peer=%d\n", pindex->GetBlockHash().ToString(),
61626176
pindex->nHeight, pto->id);

src/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static const uint64_t nRelevantServices = NODE_NETWORK | NODE_WITNESS;
7979
//
8080
bool fDiscover = true;
8181
bool fListen = true;
82-
uint64_t nLocalServices = NODE_NETWORK | NODE_WITNESS;
82+
uint64_t nLocalServices = NODE_NETWORK;
8383
CCriticalSection cs_mapLocalHost;
8484
map<CNetAddr, LocalServiceInfo> mapLocalHost;
8585
static bool vfLimited[NET_MAX] = {};

0 commit comments

Comments
 (0)