Skip to content

Commit 28749f7

Browse files
authored
Add config sequence to simple batch and Batch interface (#242)
Signed-off-by: Yoav Tock <tock@il.ibm.com>
1 parent b565a5c commit 28749f7

File tree

10 files changed

+58
-50
lines changed

10 files changed

+58
-50
lines changed

common/types/simple_batch.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,28 @@ SPDX-License-Identifier: Apache-2.0
77
package types
88

99
type SimpleBatch struct {
10-
seq BatchSequence
11-
shard ShardID
12-
primary PartyID
13-
requests BatchedRequests
14-
digest []byte
10+
shard ShardID
11+
primary PartyID
12+
seq BatchSequence
13+
digest []byte
14+
requests BatchedRequests
15+
configSequence ConfigSequence
1516
}
1617

17-
func NewSimpleBatch(seq BatchSequence, shard ShardID, primary PartyID, requests BatchedRequests) *SimpleBatch {
18+
func NewSimpleBatch(shard ShardID, primary PartyID, seq BatchSequence, requests BatchedRequests, configSequence ConfigSequence) *SimpleBatch {
1819
return &SimpleBatch{
19-
seq: seq,
20-
shard: shard,
21-
primary: primary,
22-
requests: requests,
23-
digest: requests.Digest(),
20+
seq: seq,
21+
shard: shard,
22+
primary: primary,
23+
requests: requests,
24+
digest: requests.Digest(),
25+
configSequence: configSequence,
2426
}
2527
}
2628

27-
func (sb *SimpleBatch) Digest() []byte { return sb.digest }
28-
func (sb *SimpleBatch) Requests() BatchedRequests { return sb.requests }
29-
func (sb *SimpleBatch) Primary() PartyID { return sb.primary }
30-
func (sb *SimpleBatch) Shard() ShardID { return sb.shard }
31-
func (sb *SimpleBatch) Seq() BatchSequence { return sb.seq }
29+
func (sb *SimpleBatch) Digest() []byte { return sb.digest }
30+
func (sb *SimpleBatch) Requests() BatchedRequests { return sb.requests }
31+
func (sb *SimpleBatch) Primary() PartyID { return sb.primary }
32+
func (sb *SimpleBatch) Shard() ShardID { return sb.shard }
33+
func (sb *SimpleBatch) Seq() BatchSequence { return sb.seq }
34+
func (sb *SimpleBatch) ConfigSequence() ConfigSequence { return sb.configSequence }

common/types/simple_batch_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,22 @@ import (
1414
)
1515

1616
func TestNewSimpleBatch(t *testing.T) {
17-
b1 := types.NewSimpleBatch(1, 2, 3, nil)
17+
b1 := types.NewSimpleBatch(2, 3, 1, nil, 4)
1818
assert.NotNil(t, b1)
1919
assert.Equal(t, types.BatchSequence(1), b1.Seq())
2020
assert.Equal(t, types.ShardID(2), b1.Shard())
2121
assert.Equal(t, types.PartyID(3), b1.Primary())
22+
assert.Equal(t, types.ConfigSequence(4), b1.ConfigSequence())
2223
assert.Nil(t, b1.Requests())
2324
assert.Len(t, b1.Digest(), 32)
2425
assert.Equal(t, "Sh,Pr,Sq,Dg: <2,3,1,e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855>", types.BatchIDToString(b1))
2526

26-
b2 := types.NewSimpleBatch(1, 2, 3, [][]byte{{1, 2}, {3, 4}})
27+
b2 := types.NewSimpleBatch(2, 3, 1, [][]byte{{1, 2}, {3, 4}}, 5)
2728
assert.NotNil(t, b2)
2829
assert.Equal(t, types.BatchSequence(1), b2.Seq())
2930
assert.Equal(t, types.ShardID(2), b2.Shard())
3031
assert.Equal(t, types.PartyID(3), b2.Primary())
32+
assert.Equal(t, types.ConfigSequence(5), b2.ConfigSequence())
3133
br := types.BatchedRequests([][]byte{{1, 2}, {3, 4}})
3234
assert.Equal(t, br, b2.Requests())
3335
assert.Equal(t, b2.Digest(), br.Digest())
@@ -38,4 +40,6 @@ func TestNewSimpleBatch(t *testing.T) {
3840

3941
var id types.BatchID
4042
assert.Equal(t, "<nil>", types.BatchIDToString(id))
43+
44+
assert.False(t, types.BatchIDEqual(b1, b2))
4145
}

common/types/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ type BatchAttestationFragment interface {
6969
type Batch interface {
7070
BatchID
7171
Requests() BatchedRequests
72+
ConfigSequence() ConfigSequence
7273
}
7374

7475
// OrderingInfo is an opaque object that provides extra information on the order of the batch attestation and

node/assembler/assembler_batcher_consenter_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestAssemblerHandlesConsenterReconnect(t *testing.T) {
5151
obaCreator, _ := NewOrderedBatchAttestationCreator()
5252

5353
// send batch and matching decision
54-
batch1 := types.NewSimpleBatch(0, 1, 1, types.BatchedRequests{[]byte{1}})
54+
batch1 := types.NewSimpleBatch(1, 1, 0, types.BatchedRequests{[]byte{1}}, 0)
5555
batchersStub[0].SetNextBatch(batch1)
5656

5757
oba1 := obaCreator.Append(batch1, 1, 0, 1)
@@ -65,7 +65,7 @@ func TestAssemblerHandlesConsenterReconnect(t *testing.T) {
6565
// stop consenter and send next batch
6666
consenterStub.Stop()
6767

68-
batch2 := types.NewSimpleBatch(1, 1, 1, types.BatchedRequests{[]byte{2}, []byte{3}})
68+
batch2 := types.NewSimpleBatch(1, 1, 1, types.BatchedRequests{[]byte{2}, []byte{3}}, 0)
6969
batchersStub[0].SetNextBatch(batch2)
7070

7171
// let assembler retry while consenter is down
@@ -112,7 +112,7 @@ func TestAssemblerHandlesBatcherReconnect(t *testing.T) {
112112
obaCreator, _ := NewOrderedBatchAttestationCreator()
113113

114114
// send batch and matching decision
115-
batch1 := types.NewSimpleBatch(0, 1, 1, types.BatchedRequests{[]byte{1}})
115+
batch1 := types.NewSimpleBatch(1, 1, 0, types.BatchedRequests{[]byte{1}}, 0)
116116
batchersStub[0].SetNextBatch(batch1)
117117

118118
oba1 := obaCreator.Append(batch1, 1, 0, 1)
@@ -134,7 +134,7 @@ func TestAssemblerHandlesBatcherReconnect(t *testing.T) {
134134
time.Sleep(time.Second)
135135

136136
// send next batch and decision
137-
batch2 := types.NewSimpleBatch(1, 1, 1, types.BatchedRequests{[]byte{2}, []byte{3}})
137+
batch2 := types.NewSimpleBatch(1, 1, 1, types.BatchedRequests{[]byte{2}, []byte{3}}, 0)
138138
batchersStub[0].SetNextBatch(batch2)
139139

140140
oba2 := obaCreator.Append(batch2, 2, 0, 1)
@@ -179,7 +179,7 @@ func TestAssemblerBatchProcessingAcrossParties(t *testing.T) {
179179

180180
// send batch from party 2 on shard 0
181181
// assembler (party 1) should fetch it from another party
182-
batch1 := types.NewSimpleBatch(0, 0, 2, types.BatchedRequests{[]byte{1}})
182+
batch1 := types.NewSimpleBatch(0, 2, 0, types.BatchedRequests{[]byte{1}}, 0)
183183
batchersStubShard0[1].SetNextBatch(batch1)
184184
batchersStubShard0[0].SetNextBatch(batch1)
185185

@@ -193,7 +193,7 @@ func TestAssemblerBatchProcessingAcrossParties(t *testing.T) {
193193
}, 10*time.Second, 100*time.Millisecond)
194194

195195
// send another batch and decision from party 1 on shard 0
196-
batch2 := types.NewSimpleBatch(1, 0, 2, types.BatchedRequests{[]byte{2}, []byte{3}})
196+
batch2 := types.NewSimpleBatch(0, 2, 1, types.BatchedRequests{[]byte{2}, []byte{3}}, 0)
197197
batchersStubShard0[0].SetNextBatch(batch2)
198198

199199
oba2 := obaCreator.Append(batch2, 2, 0, 1)
@@ -205,7 +205,7 @@ func TestAssemblerBatchProcessingAcrossParties(t *testing.T) {
205205
}, 3*time.Second, 100*time.Millisecond)
206206

207207
// send batch and decision from party 1 on shard 1
208-
batch3 := types.NewSimpleBatch(0, 1, 2, types.BatchedRequests{[]byte{5}})
208+
batch3 := types.NewSimpleBatch(1, 2, 0, types.BatchedRequests{[]byte{5}}, 0)
209209
batchersStubShard1[0].SetNextBatch(batch3)
210210

211211
oba3 := obaCreator.Append(batch3, 3, 0, 1)
@@ -245,7 +245,7 @@ func TestAssembler_DifferentDigestSameSeq(t *testing.T) {
245245

246246
var batches0to10 []*types.SimpleBatch
247247
// send batch 0 and decisions
248-
batch0 := types.NewSimpleBatch(0, 1, 1, types.BatchedRequests{[]byte{1}})
248+
batch0 := types.NewSimpleBatch(1, 1, 0, types.BatchedRequests{[]byte{1}}, 0)
249249
batchersStub[0].SetNextBatch(batch0)
250250
batches0to10 = append(batches0to10, batch0)
251251

@@ -259,7 +259,7 @@ func TestAssembler_DifferentDigestSameSeq(t *testing.T) {
259259

260260
// Send batch 1-10 and decisions via batcher 0
261261
for i := types.BatchSequence(1); i <= 10; i++ {
262-
batch := types.NewSimpleBatch(i, 1, 1, types.BatchedRequests{[]byte{byte(i)}})
262+
batch := types.NewSimpleBatch(1, 1, i, types.BatchedRequests{[]byte{byte(i)}}, 0)
263263
batchersStub[0].SetNextBatch(batch)
264264

265265
oba := obaCreator.Append(batch, types.DecisionNum(1+i), 0, 1)
@@ -274,7 +274,7 @@ func TestAssembler_DifferentDigestSameSeq(t *testing.T) {
274274
}
275275

276276
// Create another batch with same <Sh, Pr, Seq> = <1,1,10> but different digest
277-
batch10dup := types.NewSimpleBatch(10, 1, 1, types.BatchedRequests{[]byte{100}})
277+
batch10dup := types.NewSimpleBatch(1, 1, 10, types.BatchedRequests{[]byte{100}}, 0)
278278
require.NotEqual(t, batch10dup.Digest(), batches0to10[10].Digest())
279279

280280
// Batchers 1,2 have the same batches with sequence 0-9, but differ on the batch with sequence 10

node/assembler/assembler_role_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (r *naiveReplication) Stop() {
5050

5151
func (r *naiveReplication) Append(partyID types.PartyID, batchSeq types.BatchSequence, batchedRequests types.BatchedRequests) {
5252
for _, s := range r.subscribers {
53-
s <- types.NewSimpleBatch(batchSeq, 0, partyID, batchedRequests)
53+
s <- types.NewSimpleBatch(0, partyID, batchSeq, batchedRequests, 0)
5454
}
5555
}
5656

@@ -229,7 +229,7 @@ func TestAssembler(t *testing.T) {
229229
buff := make([]byte, 1024)
230230
binary.BigEndian.PutUint16(buff, uint16(shardID))
231231
binary.BigEndian.PutUint16(buff[100:], uint16(seq))
232-
batch := types.NewSimpleBatch(seq, shardID, 1, [][]byte{buff})
232+
batch := types.NewSimpleBatch(shardID, 1, seq, [][]byte{buff}, 0)
233233
digests[string(batch.Digest())] = struct{}{}
234234
batchesForShard = append(batchesForShard, batch)
235235
}

node/assembler/prefetch_benchmark/batch_generator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ func (bg *batchGenerator) GenerateBatch(shardId types.ShardID, primaryId types.P
4141
if !regular {
4242
requests = bg.emptyRequests
4343
}
44-
return types.NewSimpleBatch(seq, shardId, primaryId, requests)
44+
return types.NewSimpleBatch(shardId, primaryId, seq, requests, 0)
4545
}

node/assembler/utils_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
func createTestBatch(shard types.ShardID, primary types.PartyID, seq types.BatchSequence, req []byte) types.Batch {
14-
return types.NewSimpleBatch(seq, shard, primary, types.BatchedRequests{req})
14+
return types.NewSimpleBatch(shard, primary, seq, types.BatchedRequests{req}, 0)
1515
}
1616

1717
// createTestBatchWithSize creates a simple batch including requests with given size
@@ -30,9 +30,9 @@ func createTestBatchWithSize(shard types.ShardID, primary types.PartyID, seq typ
3030
for _, requestSize := range requestsBytesSize {
3131
requests = append(requests, make([]byte, requestSize))
3232
}
33-
return types.NewSimpleBatch(seq, shard, primary, requests)
33+
return types.NewSimpleBatch(shard, primary, seq, requests, 0)
3434
}
3535

3636
func createTestBatchId(shard types.ShardID, primary types.PartyID, seq types.BatchSequence, req []byte) types.BatchID {
37-
return types.NewSimpleBatch(seq, shard, primary, types.BatchedRequests{req})
37+
return types.NewSimpleBatch(shard, primary, seq, types.BatchedRequests{req}, 0)
3838
}

node/batcher/batcher_role_old_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (r *naiveReplication) Stop() {
6666

6767
func (r *naiveReplication) Append(partyID arma_types.PartyID, batchSeq arma_types.BatchSequence, batchedRequests arma_types.BatchedRequests) {
6868
for _, s := range r.subscribers {
69-
s <- arma_types.NewSimpleBatch(batchSeq, 0, partyID, batchedRequests)
69+
s <- arma_types.NewSimpleBatch(0, partyID, batchSeq, batchedRequests, 0)
7070
}
7171
}
7272

node/batcher/batcher_role_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func TestSecondaryBatcherSimple(t *testing.T) {
7878
reqs := make(arma_types.BatchedRequests, 1)
7979
reqs = append(reqs, req)
8080

81-
batch := arma_types.NewSimpleBatch(0, 0, 1, reqs)
81+
batch := arma_types.NewSimpleBatch(0, 1, 0, reqs, 0)
8282

8383
batchPuller := &mocks.FakeBatchesPuller{}
8484
batchChan := make(chan arma_types.Batch)
@@ -105,7 +105,7 @@ func TestSecondaryBatcherSimple(t *testing.T) {
105105
return ledger.AppendCallCount() == 1
106106
}, 10*time.Second, 10*time.Millisecond)
107107

108-
batch = arma_types.NewSimpleBatch(1, 0, 1, reqs)
108+
batch = arma_types.NewSimpleBatch(0, 1, 1, reqs, 0)
109109
batchChan <- batch
110110
require.Eventually(t, func() bool {
111111
return ledger.AppendCallCount() == 2
@@ -146,7 +146,7 @@ func TestPrimaryChangeToSecondary(t *testing.T) {
146146
stateProvider.GetLatestStateChanReturns(stateChan)
147147
batcher.StateProvider = stateProvider
148148

149-
batch := arma_types.NewSimpleBatch(0, 0, 2, reqs)
149+
batch := arma_types.NewSimpleBatch(0, 2, 0, reqs, 0)
150150

151151
batchPuller := &mocks.FakeBatchesPuller{}
152152
batchChan := make(chan arma_types.Batch)
@@ -228,7 +228,7 @@ func TestSecondaryChangeToPrimary(t *testing.T) {
228228
stateProvider.GetLatestStateChanReturns(stateChan)
229229
batcher.StateProvider = stateProvider
230230

231-
batch := arma_types.NewSimpleBatch(0, 0, 1, reqs)
231+
batch := arma_types.NewSimpleBatch(0, 1, 0, reqs, 0)
232232

233233
batchPuller := &mocks.FakeBatchesPuller{}
234234
batchChan := make(chan arma_types.Batch)
@@ -306,7 +306,7 @@ func TestSecondaryChangeToSecondary(t *testing.T) {
306306
reqs := make(arma_types.BatchedRequests, 1)
307307
reqs = append(reqs, req)
308308

309-
batch := arma_types.NewSimpleBatch(0, 0, 1, reqs)
309+
batch := arma_types.NewSimpleBatch(0, 1, 0, reqs, 0)
310310

311311
batchPuller := &mocks.FakeBatchesPuller{}
312312
batchChan := make(chan arma_types.Batch)
@@ -363,7 +363,7 @@ func TestSecondaryChangeToSecondary(t *testing.T) {
363363
return batchPuller.StopCallCount() == 1
364364
}, 10*time.Second, 10*time.Millisecond)
365365

366-
batch = arma_types.NewSimpleBatch(0, 0, 2, reqs)
366+
batch = arma_types.NewSimpleBatch(0, 2, 0, reqs, 0)
367367
batchChan <- batch
368368
require.Eventually(t, func() bool {
369369
return ledger.AppendCallCount() == 2
@@ -518,7 +518,7 @@ func TestPrimaryWaitingAndTermChange(t *testing.T) {
518518
stateProvider.GetLatestStateChanReturns(stateChan)
519519
batcher.StateProvider = stateProvider
520520

521-
batch := arma_types.NewSimpleBatch(0, 0, 2, reqs)
521+
batch := arma_types.NewSimpleBatch(0, 2, 0, reqs, 0)
522522

523523
batchPuller := &mocks.FakeBatchesPuller{}
524524
batchChan := make(chan arma_types.Batch)
@@ -598,7 +598,7 @@ func TestResubmitPending(t *testing.T) {
598598
stateProvider.GetLatestStateChanReturns(stateChan)
599599
batcher.StateProvider = stateProvider
600600

601-
batch := arma_types.NewSimpleBatch(0, 0, 1, reqs)
601+
batch := arma_types.NewSimpleBatch(0, 1, 0, reqs, 0)
602602

603603
batchPuller := &mocks.FakeBatchesPuller{}
604604
batchChan := make(chan arma_types.Batch)
@@ -692,7 +692,7 @@ func TestVerifyBatch(t *testing.T) {
692692
reqs := make(arma_types.BatchedRequests, 1)
693693
reqs = append(reqs, req)
694694

695-
batch := arma_types.NewSimpleBatch(0, 0, 1, reqs)
695+
batch := arma_types.NewSimpleBatch(0, 1, 0, reqs, 0)
696696

697697
batchPuller := &mocks.FakeBatchesPuller{}
698698
batchChan := make(chan arma_types.Batch)
@@ -710,25 +710,25 @@ func TestVerifyBatch(t *testing.T) {
710710
return ledger.AppendCallCount() == 1
711711
}, 10*time.Second, 10*time.Millisecond)
712712

713-
batch = arma_types.NewSimpleBatch(0, 0, 2, reqs)
713+
batch = arma_types.NewSimpleBatch(0, 2, 0, reqs, 0)
714714
batchChan <- batch
715715
require.Eventually(t, func() bool {
716716
return complainer.ComplainCallCount() == 1
717717
}, 10*time.Second, 10*time.Millisecond)
718718

719-
batch = arma_types.NewSimpleBatch(0, 1, 1, reqs)
719+
batch = arma_types.NewSimpleBatch(1, 1, 0, reqs, 0)
720720
batchChan <- batch
721721
require.Eventually(t, func() bool {
722722
return complainer.ComplainCallCount() == 2
723723
}, 10*time.Second, 10*time.Millisecond)
724724

725-
batch = arma_types.NewSimpleBatch(2, 0, 1, reqs)
725+
batch = arma_types.NewSimpleBatch(0, 1, 2, reqs, 0)
726726
batchChan <- batch
727727
require.Eventually(t, func() bool {
728728
return complainer.ComplainCallCount() == 3
729729
}, 10*time.Second, 10*time.Millisecond)
730730

731-
batch = arma_types.NewSimpleBatch(0, 0, 1, nil)
731+
batch = arma_types.NewSimpleBatch(0, 1, 0, nil, 0)
732732
batchChan <- batch
733733
require.Eventually(t, func() bool {
734734
return complainer.ComplainCallCount() == 4
@@ -741,7 +741,7 @@ func TestVerifyBatch(t *testing.T) {
741741
}, 10*time.Second, 10*time.Millisecond)
742742
verifier.VerifyBatchedRequestsReturns(nil)
743743

744-
batch = arma_types.NewSimpleBatch(1, 0, 1, reqs)
744+
batch = arma_types.NewSimpleBatch(0, 1, 1, reqs, 0)
745745
batchChan <- batch
746746
require.Eventually(t, func() bool {
747747
return ledger.AppendCallCount() == 2

node/ledger/assembler_ledger.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func (l *AssemblerLedger) AppendConfig(configBlock *common.Block, decisionNum ty
216216
}
217217

218218
transactionCount := atomic.AddUint64(&l.transactionCount, 1) // len(configBlock.GetData().GetData()) = should always be a single TX
219-
batchID := types.NewSimpleBatch(0, types.ShardIDConsensus, 0, nil)
219+
batchID := types.NewSimpleBatch(types.ShardIDConsensus, 0, 0, nil, 0)
220220
ordInfo := &state.OrderingInformation{
221221
DecisionNum: decisionNum,
222222
BatchIndex: 0,

0 commit comments

Comments
 (0)