Skip to content

Commit

Permalink
remove expiry field from non-PR messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jrick committed Mar 19, 2024
1 parent 807dbdb commit 2888ec0
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 169 deletions.
24 changes: 12 additions & 12 deletions wire/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ func TestMessage(t *testing.T) {
if err != nil {
t.Errorf("NewMsgMixPairReq: %v", err)
}
msgMixKE := NewMsgMixKeyExchange([33]byte{}, [32]byte{}, 1, 1, [33]byte{}, [1218]byte{}, [32]byte{}, []chainhash.Hash{})
msgMixCT := NewMsgMixCiphertexts([33]byte{}, [32]byte{}, 1, 1, [][1047]byte{}, []chainhash.Hash{})
msgMixSR := NewMsgMixSlotReserve([33]byte{}, [32]byte{}, 1, 1, [][][]byte{{{}}}, []chainhash.Hash{})
msgMixDC := NewMsgMixDCNet([33]byte{}, [32]byte{}, 1, 1, []MixVect{make(MixVect, 1)}, []chainhash.Hash{})
msgMixCM := NewMsgMixConfirm([33]byte{}, [32]byte{}, 1, 1, NewMsgTx(), []chainhash.Hash{})
msgMixRS := NewMsgMixSecrets([33]byte{}, [32]byte{}, 1, 1, [32]byte{}, [][]byte{}, MixVect{})
msgMixKE := NewMsgMixKeyExchange([33]byte{}, [32]byte{}, 1, [33]byte{}, [1218]byte{}, [32]byte{}, []chainhash.Hash{})
msgMixCT := NewMsgMixCiphertexts([33]byte{}, [32]byte{}, 1, [][1047]byte{}, []chainhash.Hash{})
msgMixSR := NewMsgMixSlotReserve([33]byte{}, [32]byte{}, 1, [][][]byte{{{}}}, []chainhash.Hash{})
msgMixDC := NewMsgMixDCNet([33]byte{}, [32]byte{}, 1, []MixVect{make(MixVect, 1)}, []chainhash.Hash{})
msgMixCM := NewMsgMixConfirm([33]byte{}, [32]byte{}, 1, NewMsgTx(), []chainhash.Hash{})
msgMixRS := NewMsgMixSecrets([33]byte{}, [32]byte{}, 1, [32]byte{}, [][]byte{}, MixVect{})

tests := []struct {
in Message // Value to encode
Expand Down Expand Up @@ -123,12 +123,12 @@ func TestMessage(t *testing.T) {
{msgGetInitState, msgGetInitState, pver, MainNet, 25},
{msgInitState, msgInitState, pver, MainNet, 28},
{msgMixPR, msgMixPR, pver, MainNet, 165},
{msgMixKE, msgMixKE, pver, MainNet, 1445},
{msgMixCT, msgMixCT, pver, MainNet, 162},
{msgMixSR, msgMixSR, pver, MainNet, 165},
{msgMixDC, msgMixDC, pver, MainNet, 185},
{msgMixCM, msgMixCM, pver, MainNet, 177},
{msgMixRS, msgMixRS, pver, MainNet, 196},
{msgMixKE, msgMixKE, pver, MainNet, 1441},
{msgMixCT, msgMixCT, pver, MainNet, 158},
{msgMixSR, msgMixSR, pver, MainNet, 161},
{msgMixDC, msgMixDC, pver, MainNet, 181},
{msgMixCM, msgMixCM, pver, MainNet, 173},
{msgMixRS, msgMixRS, pver, MainNet, 192},
}

t.Logf("Running %d tests", len(tests))
Expand Down
16 changes: 4 additions & 12 deletions wire/msgmixciphertexts.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ type MsgMixCiphertexts struct {
Signature [64]byte
Identity [33]byte
SessionID [32]byte
Expiry uint32
Run uint32
Ciphertexts [][1047]byte
SeenKeyExchanges []chainhash.Hash
Expand All @@ -41,7 +40,7 @@ func (msg *MsgMixCiphertexts) BtcDecode(r io.Reader, pver uint32) error {
}

err := readElements(r, &msg.Signature, &msg.Identity, &msg.SessionID,
&msg.Expiry, &msg.Run)
&msg.Run)
if err != nil {
return err
}
Expand Down Expand Up @@ -149,8 +148,7 @@ func (msg *MsgMixCiphertexts) writeMessageNoSignature(op string, w io.Writer, pv
return messageError(op, ErrTooManyPrevMixMsgs, msg)
}

err := writeElements(w, &msg.Identity, &msg.SessionID, msg.Expiry,
msg.Run)
err := writeElements(w, &msg.Identity, &msg.SessionID, msg.Run)
if err != nil {
return err
}
Expand Down Expand Up @@ -197,7 +195,7 @@ func (msg *MsgMixCiphertexts) MaxPayloadLength(pver uint32) uint32 {
}

// See tests for this calculation.
return 552588
return 552584
}

// Pub returns the message sender's public key identity.
Expand All @@ -210,11 +208,6 @@ func (msg *MsgMixCiphertexts) Sig() []byte {
return msg.Signature[:]
}

// Expires returns the block height at which the message expires.
func (msg *MsgMixCiphertexts) Expires() uint32 {
return msg.Expiry
}

// PrevMsgs returns the previous key exchange messages seen by the peer.
func (msg *MsgMixCiphertexts) PrevMsgs() []chainhash.Hash {
return msg.SeenKeyExchanges
Expand All @@ -233,13 +226,12 @@ func (msg *MsgMixCiphertexts) GetRun() uint32 {
// NewMsgMixCiphertexts returns a new mixcphrtxt message that conforms to the
// Message interface using the passed parameters and defaults for the
// remaining fields.
func NewMsgMixCiphertexts(identity [33]byte, sid [32]byte, expires uint32, run uint32,
func NewMsgMixCiphertexts(identity [33]byte, sid [32]byte, run uint32,
ciphertexts [][1047]byte, seenKeyExchanges []chainhash.Hash) *MsgMixCiphertexts {

return &MsgMixCiphertexts{
Identity: identity,
SessionID: sid,
Expiry: expires,
Run: run,
Ciphertexts: ciphertexts,
SeenKeyExchanges: seenKeyExchanges,
Expand Down
25 changes: 11 additions & 14 deletions wire/msgmixciphertexts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,19 @@ func newTestMixCiphertexts() *MsgMixCiphertexts {
id := *(*[33]byte)(repeat(0x81, 33))
sid := *(*[32]byte)(repeat(0x82, 32))

const expiry = uint32(0x83838383)
const run = uint32(0x84848484)
const run = uint32(0x83838383)

cts := make([][1047]byte, 4)
for b := byte(0x85); b < 0x89; b++ {
copy(cts[b-0x85][:], repeat(b, 1047))
for b := byte(0x84); b < 0x88; b++ {
copy(cts[b-0x84][:], repeat(b, 1047))
}

seenKEs := make([]chainhash.Hash, 4)
for b := byte(0x89); b < 0x8D; b++ {
copy(seenKEs[b-0x89][:], repeat(b, 32))
for b := byte(0x88); b < 0x8C; b++ {
copy(seenKEs[b-0x88][:], repeat(b, 32))
}

ct := NewMsgMixCiphertexts(id, sid, expiry, run, cts, seenKEs)
ct := NewMsgMixCiphertexts(id, sid, run, cts, seenKEs)
ct.Signature = sig

return ct
Expand All @@ -55,20 +54,19 @@ func TestMsgMixCiphertextsWire(t *testing.T) {
expected = append(expected, repeat(0x80, 64)...) // Signature
expected = append(expected, repeat(0x81, 33)...) // Identity
expected = append(expected, repeat(0x82, 32)...) // Session ID
expected = append(expected, repeat(0x83, 4)...) // Expiry
expected = append(expected, repeat(0x84, 4)...) // Run
expected = append(expected, repeat(0x83, 4)...) // Run
// Varint count of ciphertexts and seen KEs
expected = append(expected, 0x04)
// Four ciphextexts (repeating 1047 bytes of 0x85, 0x86, 0x87, 0x88)
// Four ciphextexts (repeating 1047 bytes of 0x84, 0x85, 0x86, 0x87)
expected = append(expected, repeat(0x84, 1047)...)
expected = append(expected, repeat(0x85, 1047)...)
expected = append(expected, repeat(0x86, 1047)...)
expected = append(expected, repeat(0x87, 1047)...)
expected = append(expected, repeat(0x88, 1047)...)
// Four seen KEs (repeating 32 bytes of 0x89, 0x8a, 0x8b, 0x8c)
// Four seen KEs (repeating 32 bytes of 0x88, 0x89, 0x8a, 0x8b)
expected = append(expected, repeat(0x88, 32)...)
expected = append(expected, repeat(0x89, 32)...)
expected = append(expected, repeat(0x8a, 32)...)
expected = append(expected, repeat(0x8b, 32)...)
expected = append(expected, repeat(0x8c, 32)...)

expectedSerializationEqual(t, buf.Bytes(), expected)

Expand Down Expand Up @@ -158,7 +156,6 @@ func TestMsgMixCiphertextsMaxPayloadLength(t *testing.T) {
var expectedLen uint32 = 64 + // Signature
33 + // Identity
32 + // Session ID
4 + // Expiry
4 + // Run
uint32(VarIntSerializeSize(MaxMixPeers)) + // Ciphextext and KE hash count
MaxMixPeers*1047 + // Ciphextexts
Expand Down
16 changes: 4 additions & 12 deletions wire/msgmixconfirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ type MsgMixConfirm struct {
Signature [64]byte
Identity [33]byte
SessionID [32]byte
Expiry uint32
Run uint32
Mix MsgTx
SeenDCNets []chainhash.Hash
Expand All @@ -44,7 +43,7 @@ func (msg *MsgMixConfirm) BtcDecode(r io.Reader, pver uint32) error {
}

err := readElements(r, &msg.Signature, &msg.Identity, &msg.SessionID,
&msg.Expiry, &msg.Run)
&msg.Run)
if err != nil {
return err
}
Expand Down Expand Up @@ -141,8 +140,7 @@ func (msg *MsgMixConfirm) writeMessageNoSignature(op string, w io.Writer, pver u
return messageError(op, ErrTooManyPrevMixMsgs, msg)
}

err := writeElements(w, &msg.Identity, &msg.SessionID, msg.Expiry,
msg.Run)
err := writeElements(w, &msg.Identity, &msg.SessionID, msg.Run)
if err != nil {
return err
}
Expand Down Expand Up @@ -188,7 +186,7 @@ func (msg *MsgMixConfirm) MaxPayloadLength(pver uint32) uint32 {
}

// See tests for this calculation.
return 1016524
return 1016520
}

// Pub returns the message sender's public key identity.
Expand All @@ -201,11 +199,6 @@ func (msg *MsgMixConfirm) Sig() []byte {
return msg.Signature[:]
}

// Expires returns the block height at which the message expires.
func (msg *MsgMixConfirm) Expires() uint32 {
return msg.Expiry
}

// PrevMsgs returns the previous DC messages seen by the peer.
func (msg *MsgMixConfirm) PrevMsgs() []chainhash.Hash {
return msg.SeenDCNets
Expand All @@ -224,7 +217,7 @@ func (msg *MsgMixConfirm) GetRun() uint32 {
// NewMsgMixConfirm returns a new mixconfirm message that conforms to the
// Message interface using the passed parameters and defaults for the
// remaining fields.
func NewMsgMixConfirm(identity [33]byte, sid [32]byte, expiry uint32, run uint32,
func NewMsgMixConfirm(identity [33]byte, sid [32]byte, run uint32,
mix *MsgTx, seenDCNets []chainhash.Hash) *MsgMixConfirm {

if mix == nil {
Expand All @@ -234,7 +227,6 @@ func NewMsgMixConfirm(identity [33]byte, sid [32]byte, expiry uint32, run uint32
return &MsgMixConfirm{
Identity: identity,
SessionID: sid,
Expiry: expiry,
Run: run,
Mix: *mix,
SeenDCNets: seenDCNets,
Expand Down
17 changes: 7 additions & 10 deletions wire/msgmixconfirm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,16 @@ func newTestMixConfirm() *MsgMixConfirm {
id := *(*[33]byte)(repeat(0x81, 33))
sid := *(*[32]byte)(repeat(0x82, 32))

const expiry = uint32(0x83838383)
const run = uint32(0x84848484)
const run = uint32(0x83838383)

mix := NewMsgTx()

seenDCs := make([]chainhash.Hash, 4)
for b := byte(0x85); b < 0x89; b++ {
copy(seenDCs[b-0x85][:], repeat(b, 32))
for b := byte(0x84); b < 0x88; b++ {
copy(seenDCs[b-0x84][:], repeat(b, 32))
}

cm := NewMsgMixConfirm(id, sid, expiry, run, mix, seenDCs)
cm := NewMsgMixConfirm(id, sid, run, mix, seenDCs)
cm.Signature = sig

return cm
Expand All @@ -52,8 +51,7 @@ func TestMsgMixConfirmWire(t *testing.T) {
expected = append(expected, repeat(0x80, 64)...) // Signature
expected = append(expected, repeat(0x81, 33)...) // Identity
expected = append(expected, repeat(0x82, 32)...) // Session ID
expected = append(expected, repeat(0x83, 4)...) // Expiry
expected = append(expected, repeat(0x84, 4)...) // Run
expected = append(expected, repeat(0x83, 4)...) // Run
expected = append(expected, []byte{ // Mix transaction
0x01, 0x00, 0x00, 0x00, // Version
0x00, // Varint for number of input transactions
Expand All @@ -62,12 +60,12 @@ func TestMsgMixConfirmWire(t *testing.T) {
0x00, 0x00, 0x00, 0x00, // Expiry
0x00, // Varint for number of input signatures
}...)
// Four seen DCs (repeating 32 bytes of 0x85, 0x86, 0x87, 0x88)
// Four seen DCs (repeating 32 bytes of 0x84, 0x85, 0x86, 0x87)
expected = append(expected, 0x04)
expected = append(expected, repeat(0x84, 32)...)
expected = append(expected, repeat(0x85, 32)...)
expected = append(expected, repeat(0x86, 32)...)
expected = append(expected, repeat(0x87, 32)...)
expected = append(expected, repeat(0x88, 32)...)

expectedSerializationEqual(t, buf.Bytes(), expected)

Expand Down Expand Up @@ -157,7 +155,6 @@ func TestMsgMixConfirmMaxPayloadLength(t *testing.T) {
var expectedLen uint32 = 64 + // Signature
33 + // Identity
32 + // Session ID
4 + // Expiry
4 + // Run
MaxBlockPayloadV3 + // Maximum transaction size
uint32(VarIntSerializeSize(MaxMixPeers)) + // DC-net count
Expand Down
16 changes: 4 additions & 12 deletions wire/msgmixdcnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ type MsgMixDCNet struct {
Signature [64]byte
Identity [33]byte
SessionID [32]byte
Expiry uint32
Run uint32
DCNet []MixVect
SeenSlotReserves []chainhash.Hash
Expand All @@ -39,7 +38,7 @@ func (msg *MsgMixDCNet) BtcDecode(r io.Reader, pver uint32) error {
}

err := readElements(r, &msg.Signature, &msg.Identity, &msg.SessionID,
&msg.Expiry, &msg.Run)
&msg.Run)
if err != nil {
return err
}
Expand Down Expand Up @@ -147,8 +146,7 @@ func (msg *MsgMixDCNet) writeMessageNoSignature(op string, w io.Writer, pver uin
return messageError(op, ErrTooManyPrevMixMsgs, msg)
}

err := writeElements(w, &msg.Identity, &msg.SessionID, msg.Expiry,
msg.Run)
err := writeElements(w, &msg.Identity, &msg.SessionID, msg.Run)
if err != nil {
return err
}
Expand Down Expand Up @@ -268,7 +266,7 @@ func (msg *MsgMixDCNet) MaxPayloadLength(pver uint32) uint32 {
}

// See tests for this calculation.
return 20988051
return 20988047
}

// Pub returns the message sender's public key identity.
Expand All @@ -281,11 +279,6 @@ func (msg *MsgMixDCNet) Sig() []byte {
return msg.Signature[:]
}

// Expires returns the block height at which the message expires.
func (msg *MsgMixDCNet) Expires() uint32 {
return msg.Expiry
}

// PrevMsgs returns the previous SR messages seen by the peer.
func (msg *MsgMixDCNet) PrevMsgs() []chainhash.Hash {
return msg.SeenSlotReserves
Expand All @@ -304,13 +297,12 @@ func (msg *MsgMixDCNet) GetRun() uint32 {
// NewMsgMixDCNet returns a new mixdcnet message that conforms to the Message
// interface using the passed parameters and defaults for the remaining
// fields.
func NewMsgMixDCNet(identity [33]byte, sid [32]byte, expiry uint32, run uint32,
func NewMsgMixDCNet(identity [33]byte, sid [32]byte, run uint32,
dcnet []MixVect, seenSlotReserves []chainhash.Hash) *MsgMixDCNet {

return &MsgMixDCNet{
Identity: identity,
SessionID: sid,
Expiry: expiry,
Run: run,
DCNet: dcnet,
SeenSlotReserves: seenSlotReserves,
Expand Down
Loading

0 comments on commit 2888ec0

Please sign in to comment.