mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-02-22 14:33:06 +01:00
Fix broadcasting witness vs legacy txs (#3841)
* Fix broadcasting witness vs legacy txs * Fix version test
This commit is contained in:
parent
155301fc1d
commit
90e01d7fc6
4 changed files with 19 additions and 15 deletions
|
@ -27,7 +27,7 @@ class VersionMessageTest extends BitcoinSUnitTest {
|
|||
val inet = InetAddress(ipArr)
|
||||
|
||||
val versionMessage = VersionMessage(MainNet, inet, inet, relay = false)
|
||||
assert(versionMessage.addressReceiveServices.nodeNone)
|
||||
assert(versionMessage.addressReceiveServices.nodeWitness)
|
||||
versionMessage.addressReceiveIpAddress must be(inet)
|
||||
versionMessage.addressReceivePort must be(MainNet.port)
|
||||
|
||||
|
|
|
@ -1414,9 +1414,9 @@ object VersionMessage extends Factory[VersionMessage] {
|
|||
val nonce = UInt64.zero
|
||||
VersionMessage(
|
||||
version = ProtocolVersion.default,
|
||||
services = ServiceIdentifier.NODE_NONE,
|
||||
services = ServiceIdentifier.NODE_WITNESS,
|
||||
timestamp = Int64(java.time.Instant.now.getEpochSecond),
|
||||
addressReceiveServices = ServiceIdentifier.NODE_NONE,
|
||||
addressReceiveServices = ServiceIdentifier.NODE_WITNESS,
|
||||
addressReceiveIpAddress = receivingIpAddress,
|
||||
addressReceivePort = network.port,
|
||||
addressTransServices = ServiceIdentifier.NODE_NETWORK,
|
||||
|
|
|
@ -100,6 +100,10 @@ sealed abstract class Transaction extends NetworkElement {
|
|||
}
|
||||
|
||||
lazy val totalOutput: CurrencyUnit = outputs.map(_.value).sum
|
||||
|
||||
def toBaseTx: BaseTransaction = {
|
||||
BaseTransaction(version, inputs, outputs, lockTime)
|
||||
}
|
||||
}
|
||||
|
||||
object Transaction extends Factory[Transaction] {
|
||||
|
@ -176,9 +180,6 @@ case object EmptyTransaction extends NonWitnessTransaction {
|
|||
override def inputs: Vector[TransactionInput] = Vector.empty
|
||||
override def outputs: Vector[TransactionOutput] = Vector.empty
|
||||
override def lockTime: UInt32 = TransactionConstants.lockTime
|
||||
|
||||
def toBaseTx: BaseTransaction =
|
||||
BaseTransaction(version, inputs, outputs, lockTime)
|
||||
}
|
||||
|
||||
case class WitnessTransaction(
|
||||
|
@ -193,10 +194,6 @@ case class WitnessTransaction(
|
|||
s"Must have same amount of inputs and witnesses in witness tx, inputs=${inputs.length} witnesses=${witness.length}"
|
||||
)
|
||||
|
||||
def toBaseTx: BaseTransaction = {
|
||||
BaseTransaction(version, inputs, outputs, lockTime)
|
||||
}
|
||||
|
||||
/** The txId for the witness transaction from satoshi's original serialization */
|
||||
override def txId: DoubleSha256Digest = {
|
||||
toBaseTx.txId
|
||||
|
|
|
@ -8,7 +8,7 @@ import org.bitcoins.core.gcs.BlockFilter
|
|||
import org.bitcoins.core.p2p._
|
||||
import org.bitcoins.crypto.DoubleSha256DigestBE
|
||||
import org.bitcoins.node.config.NodeAppConfig
|
||||
import org.bitcoins.node.models.BroadcastAbleTransactionDAO
|
||||
import org.bitcoins.node.models._
|
||||
import org.bitcoins.node.{Node, P2PLogger}
|
||||
|
||||
import scala.concurrent.{ExecutionContext, Future, Promise}
|
||||
|
@ -171,13 +171,20 @@ case class DataMessageHandler(
|
|||
getData.inventories.foreach { inv =>
|
||||
logger.debug(s"Looking for inv=$inv")
|
||||
inv.typeIdentifier match {
|
||||
case TypeIdentifier.MsgTx | TypeIdentifier.MsgWitnessTx =>
|
||||
txDAO.findByHash(inv.hash).map {
|
||||
case Some(tx) =>
|
||||
peerMsgSender.sendTransactionMessage(tx.transaction)
|
||||
case msgTx @ (TypeIdentifier.MsgTx | TypeIdentifier.MsgWitnessTx) =>
|
||||
txDAO.findByHash(inv.hash).flatMap {
|
||||
case Some(BroadcastAbleTransaction(tx)) =>
|
||||
val txToBroadcast =
|
||||
if (msgTx == TypeIdentifier.MsgTx) {
|
||||
// send non-witness serialization
|
||||
tx.toBaseTx
|
||||
} else tx // send normal serialization
|
||||
|
||||
peerMsgSender.sendTransactionMessage(txToBroadcast)
|
||||
case None =>
|
||||
logger.warn(
|
||||
s"Got request to send data with hash=${inv.hash}, but found nothing")
|
||||
Future.unit
|
||||
}
|
||||
case other @ (TypeIdentifier.MsgBlock |
|
||||
TypeIdentifier.MsgFilteredBlock |
|
||||
|
|
Loading…
Add table
Reference in a new issue