Skip to content
Snippets Groups Projects
Unverified Commit 28f9e2e9 authored by Levente Pap's avatar Levente Pap
Browse files

Continue refactoring codebase to use new message layout - WIP

parent 8e6e76a2
No related branches found
No related tags found
No related merge requests found
......@@ -245,10 +245,12 @@ func MessageFromMarshalUtil(marshalUtil *marshalutil.MarshalUtil) (result *Messa
}
// verify that parents are sorted lexicographically ASC and unique
if bytes.Compare(previousParent.Bytes(), parentID.Bytes()) > -1 {
// if parentID is EmptyMessageID, bytes.Compare returns 0 in the first iteration
if bytes.Compare(previousParent.Bytes(), parentID.Bytes()) > 0 {
err = xerrors.Errorf("parents not sorted lexicographically ascending: %w", cerrors.ErrParseBytesFailed)
return
}
previousParent = parentID
}
if len(result.strongParents) < MinStrongParentsCount {
......@@ -464,7 +466,7 @@ func (m *Message) Bytes() []byte {
var bitMask bitmask.BitMask
for i, parent := range parents {
if parent.Type == StrongParent {
bitMask.SetBit(uint(i))
bitMask = bitMask.SetBit(uint(i))
}
}
marshalUtil.WriteByte(byte(bitMask))
......
......@@ -4,6 +4,7 @@ import (
"context"
"crypto"
"crypto/ed25519"
"crypto/rand"
"sync"
"sync/atomic"
"testing"
......@@ -143,7 +144,18 @@ func TestWorkerFunc_PayloadSize(t *testing.T) {
mapdb.NewMapDB(),
[]byte(sequenceKey),
identity.GenerateLocalIdentity(),
TipSelectorFunc(func(count int) []MessageID { return []MessageID{EmptyMessageID} }),
TipSelectorFunc(func(count int) []MessageID {
return func() []MessageID {
result := make([]MessageID, 0, MaxParentsCount)
for i := 0; i < MaxParentsCount; i++ {
b := make([]byte, MessageIDLength)
_, _ = rand.Read(b)
randID, _, _ := MessageIDFromBytes(b)
result = append(result, randID)
}
return result
}()
}),
)
defer msgFactory.Shutdown()
......
......@@ -8,6 +8,7 @@ import (
"golang.org/x/xerrors"
)
// TODO: need to adjust the max size of the payload if we want to keep a message to 64 KB
// MaxSize defines the maximum allowed size of a marshaled Payload (in bytes).
const MaxSize = 65288
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment