Skip to content

Commit

Permalink
Use MassCommitment instead of Mass
Browse files Browse the repository at this point in the history
  • Loading branch information
someone235 committed Jan 18, 2025
1 parent baa7d1a commit 998d0ce
Show file tree
Hide file tree
Showing 5 changed files with 239 additions and 341 deletions.
21 changes: 11 additions & 10 deletions app/appmessage/domainconverters.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package appmessage

import (
"encoding/hex"
"github.com/pkg/errors"
"math/big"

"github.com/pkg/errors"

"github.com/kaspanet/kaspad/domain/consensus/utils/blockheader"
"github.com/kaspanet/kaspad/domain/consensus/utils/hashes"
"github.com/kaspanet/kaspad/domain/consensus/utils/utxo"
Expand Down Expand Up @@ -213,14 +214,14 @@ func RPCTransactionToDomainTransaction(rpcTransaction *RPCTransaction) (*externa
}

return &externalapi.DomainTransaction{
Version: rpcTransaction.Version,
Inputs: inputs,
Outputs: outputs,
LockTime: rpcTransaction.LockTime,
SubnetworkID: *subnetworkID,
Gas: rpcTransaction.Gas,
Mass: rpcTransaction.Mass, // BPS10 add mass
Payload: payload,
Version: rpcTransaction.Version,
Inputs: inputs,
Outputs: outputs,
LockTime: rpcTransaction.LockTime,
SubnetworkID: *subnetworkID,
Gas: rpcTransaction.Gas,
MassCommitment: rpcTransaction.Mass,
Payload: payload,
}, nil
}

Expand Down Expand Up @@ -288,7 +289,7 @@ func DomainTransactionToRPCTransaction(transaction *externalapi.DomainTransactio
LockTime: transaction.LockTime,
SubnetworkID: subnetworkID,
Gas: transaction.Gas,
Mass: transaction.Mass, // <<< BPS10 add mass
Mass: transaction.MassCommitment,
Payload: payload,
}
}
Expand Down
5 changes: 3 additions & 2 deletions domain/consensus/model/externalapi/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ type DomainTransaction struct {
Gas uint64
Payload []byte

Fee uint64
Mass uint64
Fee uint64
Mass uint64
MassCommitment uint64

// ID is a field that is used to cache the transaction ID.
// Always use consensushashing.TransactionID instead of accessing this field directly
Expand Down
17 changes: 9 additions & 8 deletions domain/consensus/utils/consensushashing/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TransactionHash(tx *externalapi.DomainTransaction) *externalapi.DomainHash
// Encode the header and hash everything prior to the number of
// transactions.
writer := hashes.NewTransactionHashWriter()
err := serializeTransaction(writer, tx, txEncodingFull)
err := serializeTransaction(writer, tx, txEncodingFull, true)
if err != nil {
// It seems like this could only happen if the writer returned an error.
// and this writer should never return an error (no allocations or possible failures)
Expand All @@ -52,7 +52,7 @@ func TransactionID(tx *externalapi.DomainTransaction) *externalapi.DomainTransac
encodingFlags = txEncodingExcludeSignatureScript
}
writer := hashes.NewTransactionIDWriter()
err := serializeTransaction(writer, tx, encodingFlags)
err := serializeTransaction(writer, tx, encodingFlags, false)
if err != nil {
// this writer never return errors (no allocations or possible failures) so errors can only come from validity checks,
// and we assume we never construct malformed transactions.
Expand All @@ -74,7 +74,7 @@ func TransactionIDs(txs []*externalapi.DomainTransaction) []*externalapi.DomainT
return txIDs
}

func serializeTransaction(w io.Writer, tx *externalapi.DomainTransaction, encodingFlags txEncoding) error {
func serializeTransaction(w io.Writer, tx *externalapi.DomainTransaction, encodingFlags txEncoding, includeMass bool) error {
err := binaryserializer.PutUint16(w, tx.Version)
if err != nil {
return err
Expand Down Expand Up @@ -126,12 +126,13 @@ func serializeTransaction(w io.Writer, tx *externalapi.DomainTransaction, encodi
return err
}

if tx.Mass > 0 { // Only serialize Mass if it's not zero
err = binaryserializer.PutUint64(w, tx.Mass)
if err != nil {
return err
if includeMass {
if tx.MassCommitment > 0 { // For backward compatibility, serialize MassCommitment only if it's not zero
err = binaryserializer.PutUint64(w, tx.Mass)
if err != nil {
return err
}
}

}

return nil
Expand Down
152 changes: 49 additions & 103 deletions infrastructure/network/netadapter/server/grpcserver/protowire/p2p.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,67 +3,61 @@ package protowire;

option go_package = "github.com/kaspanet/kaspad/protowire";

message RequestAddressesMessage{
message RequestAddressesMessage {
bool includeAllSubnetworks = 1;
SubnetworkId subnetworkId = 2;
}

message AddressesMessage{
repeated NetAddress addressList = 1;
}
message AddressesMessage { repeated NetAddress addressList = 1; }

message NetAddress{
message NetAddress {
int64 timestamp = 1;
bytes ip = 3;
uint32 port = 4;
}

message SubnetworkId{
bytes bytes = 1;
}
message SubnetworkId { bytes bytes = 1; }

message TransactionMessage{
message TransactionMessage {
uint32 version = 1;
repeated TransactionInput inputs = 2;
repeated TransactionOutput outputs = 3;
uint64 lockTime = 4;
SubnetworkId subnetworkId = 5;
uint64 gas = 6;
bytes payload = 8;
uint64 mass = 9; // <<< BPS10 - Add mass to TransactionMessage
uint64 mass = 9;
}

message TransactionInput{
message TransactionInput {
Outpoint previousOutpoint = 1;
bytes signatureScript = 2;
uint64 sequence = 3;
uint32 sigOpCount = 4;
}

message Outpoint{
message Outpoint {
TransactionId transactionId = 1;
uint32 index = 2;
}

message TransactionId{
bytes bytes = 1;
}
message TransactionId { bytes bytes = 1; }
message ScriptPublicKey {
bytes script = 1;
uint32 version = 2;
}

message TransactionOutput{
message TransactionOutput {
uint64 value = 1;
ScriptPublicKey scriptPublicKey = 2;
}

message BlockMessage{
message BlockMessage {
BlockHeader header = 1;
repeated TransactionMessage transactions = 2;
}

message BlockHeader{
message BlockHeader {
uint32 version = 1;
repeated BlockLevelParents parents = 12;
Hash hashMerkleRoot = 3;
Expand All @@ -78,66 +72,43 @@ message BlockHeader{
uint64 blueScore = 13;
}

message BlockLevelParents {
repeated Hash parentHashes = 1;
}
message BlockLevelParents { repeated Hash parentHashes = 1; }

message Hash{
bytes bytes = 1;
}
message Hash { bytes bytes = 1; }

message RequestBlockLocatorMessage{
message RequestBlockLocatorMessage {
Hash highHash = 1;
uint32 limit = 2;
}

message BlockLocatorMessage{
repeated Hash hashes = 1;
}
message BlockLocatorMessage { repeated Hash hashes = 1; }

message RequestHeadersMessage{
message RequestHeadersMessage {
Hash lowHash = 1;
Hash highHash = 2;
}

message RequestNextHeadersMessage{
}
message RequestNextHeadersMessage {}

message DoneHeadersMessage{
}
message DoneHeadersMessage {}

message RequestRelayBlocksMessage{
repeated Hash hashes = 1;
}
message RequestRelayBlocksMessage { repeated Hash hashes = 1; }

message RequestTransactionsMessage {
repeated TransactionId ids = 1;
}
message RequestTransactionsMessage { repeated TransactionId ids = 1; }

message TransactionNotFoundMessage{
TransactionId id = 1;
}
message TransactionNotFoundMessage { TransactionId id = 1; }

message InvRelayBlockMessage{
Hash hash = 1;
}
message InvRelayBlockMessage { Hash hash = 1; }

message InvTransactionsMessage{
repeated TransactionId ids = 1;
}
message InvTransactionsMessage { repeated TransactionId ids = 1; }

message PingMessage{
uint64 nonce = 1;
}
message PingMessage { uint64 nonce = 1; }

message PongMessage{
uint64 nonce = 1;
}
message PongMessage { uint64 nonce = 1; }

message VerackMessage{
}
message VerackMessage {}

message VersionMessage{
message VersionMessage {
uint32 protocolVersion = 1;
uint64 services = 2;
int64 timestamp = 3;
Expand All @@ -149,19 +120,15 @@ message VersionMessage{
string network = 10;
}

message RejectMessage{
string reason = 1;
}
message RejectMessage { string reason = 1; }

message RequestPruningPointUTXOSetMessage{
Hash pruningPointHash = 1;
}
message RequestPruningPointUTXOSetMessage { Hash pruningPointHash = 1; }

message PruningPointUtxoSetChunkMessage{
message PruningPointUtxoSetChunkMessage {
repeated OutpointAndUtxoEntryPair outpointAndUtxoEntryPairs = 1;
}

message OutpointAndUtxoEntryPair{
message OutpointAndUtxoEntryPair {
Outpoint outpoint = 1;
UtxoEntry utxoEntry = 2;
}
Expand All @@ -173,54 +140,40 @@ message UtxoEntry {
bool isCoinbase = 4;
}

message RequestNextPruningPointUtxoSetChunkMessage {
}
message RequestNextPruningPointUtxoSetChunkMessage {}

message DonePruningPointUtxoSetChunksMessage {
}
message DonePruningPointUtxoSetChunksMessage {}

message RequestIBDBlocksMessage{
repeated Hash hashes = 1;
}
message RequestIBDBlocksMessage { repeated Hash hashes = 1; }

message UnexpectedPruningPointMessage{
}
message UnexpectedPruningPointMessage {}

message IbdBlockLocatorMessage {
Hash targetHash = 1;
repeated Hash blockLocatorHashes = 2;
}

message RequestIBDChainBlockLocatorMessage{
message RequestIBDChainBlockLocatorMessage {
Hash lowHash = 1;
Hash highHash = 2;
}

message IbdChainBlockLocatorMessage {
repeated Hash blockLocatorHashes = 1;
}
message IbdChainBlockLocatorMessage { repeated Hash blockLocatorHashes = 1; }

message RequestAnticoneMessage{
message RequestAnticoneMessage {
Hash blockHash = 1;
Hash contextHash = 2;
}

message IbdBlockLocatorHighestHashMessage {
Hash highestHash = 1;
}
message IbdBlockLocatorHighestHashMessage { Hash highestHash = 1; }

message IbdBlockLocatorHighestHashNotFoundMessage {
}
message IbdBlockLocatorHighestHashNotFoundMessage {}

message BlockHeadersMessage {
repeated BlockHeader blockHeaders = 1;
}
message BlockHeadersMessage { repeated BlockHeader blockHeaders = 1; }

message RequestPruningPointAndItsAnticoneMessage {
}
message RequestPruningPointAndItsAnticoneMessage {}

message RequestNextPruningPointAndItsAnticoneBlocksMessage{
}
message RequestNextPruningPointAndItsAnticoneBlocksMessage {}

message BlockWithTrustedDataMessage {
BlockMessage block = 1;
Expand Down Expand Up @@ -258,26 +211,19 @@ message BluesAnticoneSizes {
uint32 anticoneSize = 2;
}

message DoneBlocksWithTrustedDataMessage {
}
message DoneBlocksWithTrustedDataMessage {}

message PruningPointsMessage {
repeated BlockHeader headers = 1;
}
message PruningPointsMessage { repeated BlockHeader headers = 1; }

message RequestPruningPointProofMessage {
}
message RequestPruningPointProofMessage {}

message PruningPointProofMessage {
repeated PruningPointProofHeaderArray headers = 1;
}

message PruningPointProofHeaderArray {
repeated BlockHeader headers = 1;
}
message PruningPointProofHeaderArray { repeated BlockHeader headers = 1; }

message ReadyMessage {
}
message ReadyMessage {}

message BlockWithTrustedDataV4Message {
BlockMessage block = 1;
Expand Down
Loading

0 comments on commit 998d0ce

Please sign in to comment.