Skip to content

Commit

Permalink
Bugfix: correctly calculate CommitmentSize
Browse files Browse the repository at this point in the history
This refers to the amount of space being committed to, not to the size of the ATX itself!
  • Loading branch information
lrettig committed Jul 30, 2020
1 parent a894084 commit 22ec8b0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
20 changes: 15 additions & 5 deletions api/grpcserver/grpcserver_test.go
Expand Up @@ -77,7 +77,7 @@ var (
prevAtxID = types.ATXID(types.HexToHash32("44444"))
chlng = types.HexToHash32("55555")
poetRef = []byte("66666")
npst = activation.NewNIPSTWithChallenge(&chlng, poetRef)
npst = NewNIPSTWithChallenge(&chlng, poetRef)
challenge = newChallenge(nodeID, 1, prevAtxID, prevAtxID, postGenesisEpochLayer)
globalAtx = newAtx(challenge, 5, defaultView, npst, addr1)
globalAtx2 = newAtx(challenge, 5, defaultView, npst, addr2)
Expand Down Expand Up @@ -108,6 +108,19 @@ func init() {
txAPI.returnTx[globalTx2.ID()] = globalTx2
}

func NewNIPSTWithChallenge(challenge *types.Hash32, poetRef []byte) *types.NIPST {
return &types.NIPST{
Space: commitmentSize,
NipstChallenge: challenge,
PostProof: &types.PostProof{
Challenge: poetRef,
MerkleRoot: []byte(nil),
ProofNodes: [][]byte(nil),
ProvenLeaves: [][]byte(nil),
},
}
}

type NetworkMock struct {
lock sync.Mutex
broadCastErr bool
Expand Down Expand Up @@ -1702,9 +1715,6 @@ func checkLayer(t *testing.T, l *pb.Layer) {
require.Equal(t, blkPerLayer, len(l.Blocks), "unexpected number of blocks in layer")
require.Equal(t, stateRoot.Bytes(), l.RootStateHash, "unexpected state root")

data, err := globalAtx.InnerBytes()
require.NoError(t, err, "error getting activation data size")

// The order of the activations is not deterministic since they're
// stored in a map, and randomized each run. Check if either matches.
require.Condition(t, func() bool {
Expand All @@ -1725,7 +1735,7 @@ func checkLayer(t *testing.T, l *pb.Layer) {
if bytes.Compare(a.PrevAtx.Id, globalAtx.PrevATXID.Bytes()) != 0 {
continue
}
if a.CommitmentSize != uint64(len(data)) {
if a.CommitmentSize != globalAtx.Nipst.Space {
continue
}
// found a match
Expand Down
9 changes: 1 addition & 8 deletions api/grpcserver/mesh_service.go
Expand Up @@ -259,20 +259,13 @@ func convertTransaction(t *types.Transaction) *pb.Transaction {
}

func convertActivation(a *types.ActivationTx) (*pb.Activation, error) {
// TODO: It's suboptimal to have to serialize every atx to get its
// size but size is not stored as an attribute.
// See https://github.com/spacemeshos/go-spacemesh/issues/2095
data, err := a.InnerBytes()
if err != nil {
return nil, err
}
return &pb.Activation{
Id: &pb.ActivationId{Id: a.ID().Bytes()},
Layer: a.PubLayerID.Uint64(),
SmesherId: &pb.SmesherId{Id: a.NodeID.ToBytes()},
Coinbase: &pb.AccountId{Address: a.Coinbase.Bytes()},
PrevAtx: &pb.ActivationId{Id: a.PrevATXID.Bytes()},
CommitmentSize: uint64(len(data)),
CommitmentSize: a.Nipst.Space,
}, nil
}

Expand Down

0 comments on commit 22ec8b0

Please sign in to comment.