En Bitcoin Core, ¿cuándo se fAllowWitness
evalúa como true
?
const bool fAllowWitness = !(s.GetVersion() & SERIALIZE_TRANSACTION_NO_WITNESS);
En particular, no puedo calcular el valor des.GetVersion()
Gracias
Hacer un grep en SERIALIZE_TRANSACTION_NO_WITNESS
muestra que está OReado PROTOCOL_VERSION
cuando se crea un CDataStream
objeto, por ejemplo. Esta es la primera pista de que el indicador de ausencia de testigo se encuentra junto con el protocolo de versión.
Un poco más de excavación muestra que esta definición se usa cuando se crea un mensaje Tx en las líneas 1105-1126 de net_processing.cpp (v0.15.0.1) :
else if (inv.type == MSG_TX || inv.type == MSG_WITNESS_TX)
{
// Send stream from relay memory
bool push = false;
auto mi = mapRelay.find(inv.hash);
int nSendFlags = (inv.type == MSG_TX ? SERIALIZE_TRANSACTION_NO_WITNESS : 0);
if (mi != mapRelay.end()) {
connman.PushMessage(pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *mi->second));
push = true;
} else if (pfrom->timeLastMempoolReq) {
auto txinfo = mempool.info(inv.hash);
// To protect privacy, do not answer getdata using the mempool when
// that TX couldn't have been INVed in reply to a MEMPOOL request.
if (txinfo.tx && txinfo.nTime <= pfrom->timeLastMempoolReq) {
connman.PushMessage(pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *txinfo.tx));
push = true;
}
}
if (!push) {
vNotFound.push_back(inv);
}
}
El código anterior muestra que la int
variable nSendFlags
puede contener el indicador de no testigo. Posteriormente, msgMaker.Make
usará esta variable para crear el mensaje Tx como se muestra en la línea 1119 :
connman.PushMessage(pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *txinfo.tx));
Luego puede seguir la serialización mirando la clase CNetMsgMaker
en netmessagemaker.h
la que se utiliza CVectorWriter
para serializar los datos.
Para resumir, el GetVersion()
valor se construye usando la versión del protocolo opcionalmente ORed con el SERIALIZE_TRANSACTION_NO_WITNESS
. Este valor nunca se envía por cable. Se usa solo para controlar la serialización del mensaje Tx.