From 1a2a591c12d45c050a0b2c4c8b2da9df7d277f72 Mon Sep 17 00:00:00 2001 From: Ian Shim <100327837+ian-shim@users.noreply.github.com> Date: Tue, 9 Apr 2024 12:29:26 -0700 Subject: [PATCH] Update signature aggregation test (#322) Co-authored-by: Robert Raynor <35671663+mooselumph@users.noreply.github.com> --- clients/tests/retrieval_client_test.go | 12 +- core/aggregation.go | 21 +- core/aggregation_test.go | 60 ++++-- core/assignment.go | 6 + core/assignment_test.go | 56 +++--- core/mock/state.go | 209 +++++++++++--------- core/test/core_test.go | 6 +- core/thegraph/state_test.go | 24 ++- disperser/batcher/batcher_test.go | 6 +- disperser/batcher/encoding_streamer_test.go | 18 +- disperser/dataapi/server_test.go | 8 +- disperser/encoder/server_test.go | 6 +- node/grpc/server_test.go | 12 +- retriever/server_test.go | 6 +- test/integration_test.go | 6 +- 15 files changed, 293 insertions(+), 163 deletions(-) diff --git a/clients/tests/retrieval_client_test.go b/clients/tests/retrieval_client_test.go index adfe780d16..a2ecd29abc 100644 --- a/clients/tests/retrieval_client_test.go +++ b/clients/tests/retrieval_client_test.go @@ -71,12 +71,20 @@ var ( func setup(t *testing.T) { var err error - chainState, err = coremock.MakeChainDataMock(core.OperatorIndex(numOperators)) + chainState, err = coremock.MakeChainDataMock(map[uint8]int{ + 0: numOperators, + 1: numOperators, + 2: numOperators, + }) if err != nil { t.Fatalf("failed to create new mocked chain data: %s", err) } - indexedChainState, err = coremock.MakeChainDataMock(core.OperatorIndex(numOperators)) + indexedChainState, err = coremock.MakeChainDataMock(map[uint8]int{ + 0: numOperators, + 1: numOperators, + 2: numOperators, + }) if err != nil { t.Fatalf("failed to create new mocked indexed chain data: %s", err) } diff --git a/core/aggregation.go b/core/aggregation.go index 42bd556bd9..b59ff835e6 100644 --- a/core/aggregation.go +++ b/core/aggregation.go @@ -146,17 +146,16 @@ func (a *StdSignatureAggregator) AggregateSignatures(ctx context.Context, state } operatorQuorums := make([]uint8, 0, len(quorumIDs)) - for ind, id := range quorumIDs { + for ind, quorumID := range quorumIDs { // Get stake amounts for operator - ops := state.Operators[id] + ops := state.Operators[quorumID] opInfo, ok := ops[r.Operator] - // If operator is not in quorum, skip if !ok { - a.Logger.Debug("Operator not found in quorum", "operatorID", operatorIDHex, "operatorAddress", operatorAddr, "socket", socket, "quorumID", id) + a.Logger.Error("Operator not found in quorum", "operatorID", operatorIDHex, "operatorAddress", operatorAddr, "socket", socket, "quorumID", quorumID) continue } - operatorQuorums = append(operatorQuorums, id) + operatorQuorums = append(operatorQuorums, quorumID) signerMap[r.Operator] = true @@ -192,21 +191,21 @@ func (a *StdSignatureAggregator) AggregateSignatures(ctx context.Context, state // Validate the amount signed and aggregate signatures for each quorum quorumResults := make(map[QuorumID]*QuorumResult) - for ind, id := range quorumIDs { + for ind, quorumID := range quorumIDs { // Check that quorum has sufficient stake - percent := GetSignedPercentage(state.OperatorState, id, stakeSigned[ind]) - quorumResults[id] = &QuorumResult{ - QuorumID: id, + percent := GetSignedPercentage(state.OperatorState, quorumID, stakeSigned[ind]) + quorumResults[quorumID] = &QuorumResult{ + QuorumID: quorumID, PercentSigned: percent, } // Verify that the aggregated public key for the quorum matches the on-chain quorum aggregate public key sans non-signers of the quorum - quorumAggKey := state.AggKeys[id] + quorumAggKey := state.AggKeys[quorumID] quorumAggPubKeys[ind] = quorumAggKey signersAggKey := quorumAggKey.Clone() for opInd, nsk := range nonSignerKeys { - ops := state.Operators[id] + ops := state.Operators[quorumID] if _, ok := ops[nonSignerOperatorIds[opInd]]; ok { signersAggKey.Sub(nsk) } diff --git a/core/aggregation_test.go b/core/aggregation_test.go index 4f6ff6728c..20ae2e45ed 100644 --- a/core/aggregation_test.go +++ b/core/aggregation_test.go @@ -23,7 +23,10 @@ var ( func TestMain(m *testing.M) { var err error - dat, err = mock.MakeChainDataMock(10) + dat, err = mock.MakeChainDataMock(map[uint8]int{ + 0: 6, + 1: 3, + }) if err != nil { panic(err) } @@ -47,7 +50,7 @@ func simulateOperators(state mock.PrivateOperatorState, message [32]byte, update // In real life, the ordering will be random, but we simulate the signing in a fixed order // to simulate stakes deterministically for i := 0; i < len(state.PrivateOperators); i++ { - id := makeOperatorId(i) + id := mock.MakeOperatorId(i) op := state.PrivateOperators[id] sig := op.KeyPair.SignMessage(message) if count < len(state.IndexedOperators)-int(advCount) { @@ -75,7 +78,7 @@ func TestAggregateSignaturesStatus(t *testing.T) { quorums []core.QuorumResult adversaryCount uint expectedErr error - meetsQuorum bool + meetsQuorum []bool }{ { name: "Succeeds when all operators sign at quorum threshold 100", @@ -87,22 +90,22 @@ func TestAggregateSignaturesStatus(t *testing.T) { }, adversaryCount: 0, expectedErr: nil, - meetsQuorum: true, + meetsQuorum: []bool{true}, }, { - name: "Succeeds when 9/10 operators sign at quorum threshold 80", + name: "Succeeds when 5/6 operators sign at quorum threshold 70", quorums: []core.QuorumResult{ { QuorumID: 0, - PercentSigned: 80, + PercentSigned: 70, }, }, adversaryCount: 1, expectedErr: nil, - meetsQuorum: true, + meetsQuorum: []bool{true}, }, { - name: "Fails when 8/10 operators sign at quorum threshold 90", + name: "Fails when 4/6 operators sign at quorum threshold 90", quorums: []core.QuorumResult{ { QuorumID: 0, @@ -111,14 +114,45 @@ func TestAggregateSignaturesStatus(t *testing.T) { }, adversaryCount: 2, expectedErr: nil, - meetsQuorum: false, + meetsQuorum: []bool{false}, + }, + { + name: "Fails when 5/6 operators sign at quorum threshold 80 for 2 quorums", + quorums: []core.QuorumResult{ + { + QuorumID: 0, + PercentSigned: 80, + }, + { + QuorumID: 1, + PercentSigned: 80, + }, + }, + adversaryCount: 1, + expectedErr: nil, + meetsQuorum: []bool{false, true}, + }, + { + name: "Succeeds when 5/6 operators sign at quorum threshold 70 and 100", + quorums: []core.QuorumResult{ + { + QuorumID: 0, + PercentSigned: 70, + }, + { + QuorumID: 1, + PercentSigned: 100, + }, + }, + adversaryCount: 1, + expectedErr: nil, + meetsQuorum: []bool{true, true}, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - - state := dat.GetTotalOperatorState(context.Background(), 0) + state := dat.GetTotalOperatorStateWithQuorums(context.Background(), 0, []core.QuorumID{0, 1}) update := make(chan core.SignerMessage) message := [32]byte{1, 2, 3, 4, 5, 6} @@ -133,8 +167,8 @@ func TestAggregateSignaturesStatus(t *testing.T) { sigAgg, err := agg.AggregateSignatures(context.Background(), state.IndexedOperatorState, quorumIDs, message, update) assert.NoError(t, err) - for _, quorum := range tt.quorums { - if tt.meetsQuorum { + for i, quorum := range tt.quorums { + if tt.meetsQuorum[i] { assert.GreaterOrEqual(t, sigAgg.QuorumResults[quorum.QuorumID].PercentSigned, quorum.PercentSigned) } else { assert.Less(t, sigAgg.QuorumResults[quorum.QuorumID].PercentSigned, quorum.PercentSigned) diff --git a/core/assignment.go b/core/assignment.go index ebecfe4453..431428e641 100644 --- a/core/assignment.go +++ b/core/assignment.go @@ -104,6 +104,12 @@ func (c *StdAssignmentCoordinator) GetAssignments(state *OperatorState, blobLeng num := new(big.Int).Mul(big.NewInt(int64(blobLength*percentMultiplier)), r.Stake) gammaChunkLength := big.NewInt(int64(info.ChunkLength) * int64((info.ConfirmationThreshold - info.AdversaryThreshold))) + if gammaChunkLength.Cmp(big.NewInt(0)) <= 0 { + return nil, AssignmentInfo{}, fmt.Errorf("gammaChunkLength must be greater than 0") + } + if totalStakes.Cmp(big.NewInt(0)) == 0 { + return nil, AssignmentInfo{}, fmt.Errorf("total stake in quorum %d must be greater than 0", quorum) + } denom := new(big.Int).Mul(gammaChunkLength, totalStakes) if denom.Cmp(big.NewInt(0)) == 0 { return nil, AssignmentInfo{}, fmt.Errorf("gammaChunkLength %d and total stake %d in quorum %d must be greater than 0", gammaChunkLength, totalStakes, quorum) diff --git a/core/assignment_test.go b/core/assignment_test.go index 130781f711..656f03952f 100644 --- a/core/assignment_test.go +++ b/core/assignment_test.go @@ -12,12 +12,6 @@ import ( "github.com/stretchr/testify/assert" ) -func makeOperatorId(id int) core.OperatorID { - data := [32]byte{} - copy(data[:], []byte(fmt.Sprintf("%d", id))) - return data -} - func TestOperatorAssignments(t *testing.T) { state := dat.GetTotalOperatorState(context.Background(), 0) @@ -38,49 +32,49 @@ func TestOperatorAssignments(t *testing.T) { assignments, info, err := coordinator.GetAssignments(operatorState, blobLength, quorumInfo) assert.NoError(t, err) expectedAssignments := map[core.OperatorID]core.Assignment{ - makeOperatorId(0): { + mock.MakeOperatorId(0): { StartIndex: 0, NumChunks: 1, }, - makeOperatorId(1): { + mock.MakeOperatorId(1): { StartIndex: 1, - NumChunks: 1, - }, - makeOperatorId(2): { - StartIndex: 2, NumChunks: 2, }, - makeOperatorId(3): { - StartIndex: 4, - NumChunks: 2, + mock.MakeOperatorId(2): { + StartIndex: 3, + NumChunks: 3, }, - makeOperatorId(4): { + mock.MakeOperatorId(3): { StartIndex: 6, - NumChunks: 2, + NumChunks: 4, }, - makeOperatorId(5): { - StartIndex: 8, - NumChunks: 3, + mock.MakeOperatorId(4): { + StartIndex: 10, + NumChunks: 5, }, - makeOperatorId(6): { - StartIndex: 11, + mock.MakeOperatorId(5): { + StartIndex: 15, + NumChunks: 6, + }, + mock.MakeOperatorId(6): { + StartIndex: 21, NumChunks: 3, }, - makeOperatorId(7): { + mock.MakeOperatorId(7): { StartIndex: 14, NumChunks: 3, }, - makeOperatorId(8): { + mock.MakeOperatorId(8): { StartIndex: 17, NumChunks: 4, }, - makeOperatorId(9): { + mock.MakeOperatorId(9): { StartIndex: 21, NumChunks: 4, }, } expectedInfo := core.AssignmentInfo{ - TotalChunks: 25, + TotalChunks: 21, } assert.Equal(t, expectedInfo, info) @@ -119,16 +113,18 @@ func FuzzOperatorAssignments(f *testing.F) { } for i := 0; i < 100; i++ { - f.Add(rand.Intn(1000)+1, rand.Intn(2) == 0) + f.Add(rand.Intn(254)+1, rand.Intn(2) == 0) } f.Fuzz(func(t *testing.T, numOperators int, useTargetNumChunks bool) { // Generate a random slice of integers of length n - stakes := make([]int, numOperators) - for i := range stakes { - stakes[i] = rand.Intn(100) + stakes := map[core.QuorumID]map[core.OperatorID]int{ + 0: {}, + } + for i := 0; i < numOperators; i++ { + stakes[0][mock.MakeOperatorId(i)] = rand.Intn(100) + 1 } advThreshold := rand.Intn(99) diff --git a/core/mock/state.go b/core/mock/state.go index bce00910df..324febd621 100644 --- a/core/mock/state.go +++ b/core/mock/state.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "math/big" + "sort" "github.com/Layr-Labs/eigenda/core" "github.com/stretchr/testify/mock" @@ -12,17 +13,15 @@ import ( type ChainDataMock struct { mock.Mock - KeyPairs []*core.KeyPair - NumOperators core.OperatorIndex - - Stakes []int + KeyPairs map[core.OperatorID]*core.KeyPair + Operators []core.OperatorID + Stakes map[core.QuorumID]map[core.OperatorID]int } var _ core.ChainState = (*ChainDataMock)(nil) var _ core.IndexedChainState = (*ChainDataMock)(nil) type PrivateOperatorInfo struct { - *core.OperatorInfo *core.IndexedOperatorInfo KeyPair *core.KeyPair Host string @@ -36,149 +35,179 @@ type PrivateOperatorState struct { PrivateOperators map[core.OperatorID]*PrivateOperatorInfo } -func makeOperatorId(id int) core.OperatorID { - data := [32]byte{} - copy(data[:], []byte(fmt.Sprintf("%d", id))) +func MakeOperatorId(id int) core.OperatorID { + data := [32]byte{uint8(id)} return data } -func NewChainDataMock(stakes []int) (*ChainDataMock, error) { - numOperators := uint(len(stakes)) +func NewChainDataMock(stakes map[core.QuorumID]map[core.OperatorID]int) (*ChainDataMock, error) { + + seenOperators := make(map[core.OperatorID]struct{}) + for _, oprStakes := range stakes { + for opID := range oprStakes { + if _, ok := seenOperators[opID]; ok { + continue + } + seenOperators[opID] = struct{}{} + } + } + + operators := make([]core.OperatorID, 0, len(seenOperators)) + for opID := range seenOperators { + operators = append(operators, opID) + } + + sort.Slice(operators, func(i, j int) bool { + return operators[i].Hex() < operators[j].Hex() + }) - keyPairs := make([]*core.KeyPair, numOperators) - for ind := core.OperatorIndex(0); ind < numOperators; ind++ { + keyPairs := make(map[core.OperatorID]*core.KeyPair) + for _, opID := range operators { keyPair, err := core.GenRandomBlsKeys() if err != nil { return nil, err } - keyPairs[ind] = keyPair + keyPairs[opID] = keyPair } return &ChainDataMock{ - NumOperators: numOperators, - KeyPairs: keyPairs, - Stakes: stakes, + KeyPairs: keyPairs, + Operators: operators, + Stakes: stakes, }, nil - } -func MakeChainDataMock(numOperators core.OperatorIndex) (*ChainDataMock, error) { - - stakes := make([]int, numOperators) - for ind := core.OperatorIndex(0); ind < numOperators; ind++ { - stakes[ind] = int(ind + 1) +// MakeChainDataMock creates a ChainDataMock with a given number of operators per quorum +// For example, given +// +// numOperatorsPerQuorum = map[core.QuorumID]int{ +// 0: 2, +// 1: 3, +// } +// +// It will create a ChainDataMock with 2 operators in quorum 0 and 3 operators in quorum 1 +// with stakes distributed as +// +// map[core.QuorumID]map[core.OperatorID]int{ +// 0: { +// core.OperatorID{0}: 1, +// core.OperatorID{1}: 2, +// }, +// 1: { +// core.OperatorID{0}: 1, +// core.OperatorID{1}: 2, +// core.OperatorID{2}: 3, +// }, +// } +func MakeChainDataMock(numOperatorsPerQuorum map[core.QuorumID]int) (*ChainDataMock, error) { + stakes := make(map[core.QuorumID]map[core.OperatorID]int) + for quorumID, numOpr := range numOperatorsPerQuorum { + stakes[quorumID] = make(map[core.OperatorID]int) + for i := 0; i < numOpr; i++ { + id := MakeOperatorId(i) + stakes[quorumID][id] = int(i + 1) + } } - return NewChainDataMock(stakes) + return NewChainDataMock(stakes) } func (d *ChainDataMock) GetTotalOperatorState(ctx context.Context, blockNumber uint) *PrivateOperatorState { return d.GetTotalOperatorStateWithQuorums(ctx, blockNumber, []core.QuorumID{}) } -func (d *ChainDataMock) GetTotalOperatorStateWithQuorums(ctx context.Context, blockNumber uint, quorums []core.QuorumID) *PrivateOperatorState { - indexedOperators := make(map[core.OperatorID]*core.IndexedOperatorInfo, d.NumOperators) - storedOperators := make(map[core.OperatorID]*core.OperatorInfo) - privateOperators := make(map[core.OperatorID]*PrivateOperatorInfo, d.NumOperators) - - var aggPubKey *core.G1Point +func (d *ChainDataMock) GetTotalOperatorStateWithQuorums(ctx context.Context, blockNumber uint, filterQuorums []core.QuorumID) *PrivateOperatorState { + quorums := filterQuorums + if len(quorums) == 0 { + for quorumID := range d.Stakes { + quorums = append(quorums, quorumID) + } + } - quorumStake := 0 + indexedOperators := make(map[core.OperatorID]*core.IndexedOperatorInfo, len(d.Operators)) + privateOperators := make(map[core.OperatorID]*PrivateOperatorInfo, len(d.Operators)) - for ind := core.OperatorIndex(0); ind < d.NumOperators; ind++ { - if ind == 0 { - key := d.KeyPairs[ind].GetPubKeyG1() - aggPubKey = key.Clone() - } else { - aggPubKey.Add(d.KeyPairs[ind].GetPubKeyG1()) - } + aggPubKeys := make(map[core.QuorumID]*core.G1Point) + for i, id := range d.Operators { - stake := d.Stakes[ind] host := "0.0.0.0" - dispersalPort := fmt.Sprintf("3%03v", int(2*ind)) - retrievalPort := fmt.Sprintf("3%03v", int(2*ind+1)) + dispersalPort := fmt.Sprintf("3%03v", 2*i) + retrievalPort := fmt.Sprintf("3%03v", 2*i+1) socket := core.MakeOperatorSocket(host, dispersalPort, retrievalPort) - stored := &core.OperatorInfo{ - Stake: big.NewInt(int64(stake)), - Index: ind, - } - indexed := &core.IndexedOperatorInfo{ Socket: string(socket), - PubkeyG1: d.KeyPairs[ind].GetPubKeyG1(), - PubkeyG2: d.KeyPairs[ind].GetPubKeyG2(), + PubkeyG1: d.KeyPairs[id].GetPubKeyG1(), + PubkeyG2: d.KeyPairs[id].GetPubKeyG2(), } private := &PrivateOperatorInfo{ - OperatorInfo: stored, IndexedOperatorInfo: indexed, - KeyPair: d.KeyPairs[ind], + KeyPair: d.KeyPairs[id], Host: host, DispersalPort: dispersalPort, RetrievalPort: retrievalPort, } - id := makeOperatorId(int(ind)) - storedOperators[id] = stored indexedOperators[id] = indexed privateOperators[id] = private + } - quorumStake += int(stake) + storedOperators := make(map[core.QuorumID]map[core.OperatorID]*core.OperatorInfo, len(d.Stakes)) + totals := make(map[core.QuorumID]*core.OperatorInfo) - } + for _, quorumID := range quorums { - totals := map[core.QuorumID]*core.OperatorInfo{ - 0: { - Stake: big.NewInt(int64(quorumStake)), - Index: d.NumOperators, - }, - 1: { - Stake: big.NewInt(int64(quorumStake)), - Index: d.NumOperators, - }, - 2: { - Stake: big.NewInt(int64(quorumStake)), - Index: d.NumOperators, - }, - } + storedOperators[quorumID] = make(map[core.OperatorID]*core.OperatorInfo, len(d.Stakes[quorumID])) + + index := uint(0) + for _, opID := range d.Operators { + stake, ok := d.Stakes[quorumID][opID] + if !ok { + continue + } - if len(quorums) > 0 { - totals = make(map[core.QuorumID]*core.OperatorInfo) - for _, id := range quorums { - totals[id] = &core.OperatorInfo{ - Stake: big.NewInt(int64(quorumStake)), - Index: d.NumOperators, + storedOperators[quorumID][opID] = &core.OperatorInfo{ + Stake: big.NewInt(int64(stake)), + Index: index, } + index++ } - } - operators := map[core.QuorumID]map[core.OperatorID]*core.OperatorInfo{ - 0: storedOperators, - 1: storedOperators, - 2: storedOperators, - } - if len(quorums) > 0 { - operators = make(map[core.QuorumID]map[core.OperatorID]*core.OperatorInfo) - for _, id := range quorums { - operators[id] = storedOperators + quorumStake := 0 + for _, stake := range d.Stakes[quorumID] { + quorumStake += stake + } + totals[quorumID] = &core.OperatorInfo{ + Stake: big.NewInt(int64(quorumStake)), + Index: uint(len(d.Stakes[quorumID])), } } operatorState := &core.OperatorState{ - Operators: operators, + Operators: storedOperators, Totals: totals, BlockNumber: blockNumber, } + for quorumID, operatorsByID := range storedOperators { + for opID := range operatorsByID { + if aggPubKeys[quorumID] == nil { + key := privateOperators[opID].KeyPair.GetPubKeyG1() + aggPubKeys[quorumID] = key.Clone() + } else { + aggPubKeys[quorumID].Add(privateOperators[opID].KeyPair.GetPubKeyG1()) + } + } + } + indexedState := &core.IndexedOperatorState{ OperatorState: operatorState, IndexedOperators: indexedOperators, - AggKeys: map[core.QuorumID]*core.G1Point{ - 0: aggPubKey, - 1: aggPubKey, - 2: aggPubKey, - }, + AggKeys: make(map[core.QuorumID]*core.G1Point), + } + for quorumID, apk := range aggPubKeys { + indexedState.AggKeys[quorumID] = apk } privateOperatorState := &PrivateOperatorState{ @@ -192,11 +221,9 @@ func (d *ChainDataMock) GetTotalOperatorStateWithQuorums(ctx context.Context, bl } func (d *ChainDataMock) GetOperatorState(ctx context.Context, blockNumber uint, quorums []core.QuorumID) (*core.OperatorState, error) { - state := d.GetTotalOperatorStateWithQuorums(ctx, blockNumber, quorums) return state.OperatorState, nil - } func (d *ChainDataMock) GetOperatorStateByOperator(ctx context.Context, blockNumber uint, operator core.OperatorID) (*core.OperatorState, error) { diff --git a/core/test/core_test.go b/core/test/core_test.go index 3ce87c66ab..04dd74a79e 100644 --- a/core/test/core_test.go +++ b/core/test/core_test.go @@ -89,7 +89,11 @@ func makeTestBlob(t *testing.T, length int, securityParams []*core.SecurityParam // These are the products that a disperser will need in order to disperse data to the DA nodes. func prepareBatch(t *testing.T, operatorCount uint, blobs []core.Blob, bn uint) ([]core.EncodedBlob, core.BatchHeader, *mock.ChainDataMock) { - cst, err := mock.MakeChainDataMock(core.OperatorIndex(operatorCount)) + cst, err := mock.MakeChainDataMock(map[uint8]int{ + 0: int(operatorCount), + 1: int(operatorCount), + 2: int(operatorCount), + }) assert.NoError(t, err) batchHeader := core.BatchHeader{ diff --git a/core/thegraph/state_test.go b/core/thegraph/state_test.go index efff5e7e09..f9fcf4f0af 100644 --- a/core/thegraph/state_test.go +++ b/core/thegraph/state_test.go @@ -28,7 +28,11 @@ func (m mockGraphQLQuerier) Query(ctx context.Context, q any, variables map[stri func TestIndexedChainState_GetIndexedOperatorState(t *testing.T) { logger := logging.NewNoopLogger() - chainState, _ := mock.MakeChainDataMock(1) + chainState, _ := mock.MakeChainDataMock(map[uint8]int{ + 0: 1, + 1: 1, + 2: 1, + }) chainState.On("GetCurrentBlockNumber").Return(uint(1), nil) state, err := chainState.GetOperatorState(context.Background(), 1, quorums) @@ -91,7 +95,11 @@ func TestIndexedChainState_GetIndexedOperatorState(t *testing.T) { func TestIndexedChainState_GetIndexedOperatorStateMissingOperator(t *testing.T) { logger := logging.NewNoopLogger() - chainState, _ := mock.MakeChainDataMock(2) + chainState, _ := mock.MakeChainDataMock(map[uint8]int{ + 0: 2, + 1: 2, + 2: 2, + }) chainState.On("GetCurrentBlockNumber").Return(uint(1), nil) state, err := chainState.GetOperatorState(context.Background(), 1, quorums) @@ -154,7 +162,11 @@ func TestIndexedChainState_GetIndexedOperatorStateMissingOperator(t *testing.T) func TestIndexedChainState_GetIndexedOperatorStateExtraOperator(t *testing.T) { logger := logging.NewNoopLogger() - chainState, _ := mock.MakeChainDataMock(1) + chainState, _ := mock.MakeChainDataMock(map[uint8]int{ + 0: 1, + 1: 1, + 2: 1, + }) chainState.On("GetCurrentBlockNumber").Return(uint(1), nil) state, err := chainState.GetOperatorState(context.Background(), 1, quorums) @@ -233,7 +245,11 @@ func TestIndexedChainState_GetIndexedOperatorStateExtraOperator(t *testing.T) { func TestIndexedChainState_GetIndexedOperatorInfoByOperatorId(t *testing.T) { logger := logging.NewNoopLogger() - chainState, _ := mock.MakeChainDataMock(1) + chainState, _ := mock.MakeChainDataMock(map[uint8]int{ + 0: 1, + 1: 1, + 2: 1, + }) chainState.On("GetCurrentBlockNumber").Return(uint(1), nil) state, err := chainState.GetOperatorState(context.Background(), 1, quorums) diff --git a/disperser/batcher/batcher_test.go b/disperser/batcher/batcher_test.go index ab44ccbe3e..a42fe35f0d 100644 --- a/disperser/batcher/batcher_test.go +++ b/disperser/batcher/batcher_test.go @@ -77,7 +77,11 @@ func makeBatcher(t *testing.T) (*batcherComponents, *bat.Batcher, func() []time. finalizationBlockDelay := uint(75) // Core Components - cst, err := coremock.MakeChainDataMock(10) + cst, err := coremock.MakeChainDataMock(map[uint8]int{ + 0: 10, + 1: 10, + 2: 10, + }) assert.NoError(t, err) cst.On("GetCurrentBlockNumber").Return(uint(10)+finalizationBlockDelay, nil) asgn := &core.StdAssignmentCoordinator{} diff --git a/disperser/batcher/encoding_streamer_test.go b/disperser/batcher/encoding_streamer_test.go index 291b069e51..75a5461b01 100644 --- a/disperser/batcher/encoding_streamer_test.go +++ b/disperser/batcher/encoding_streamer_test.go @@ -41,7 +41,11 @@ type components struct { func createEncodingStreamer(t *testing.T, initialBlockNumber uint, batchThreshold uint64, streamerConfig batcher.StreamerConfig) (*batcher.EncodingStreamer, *components) { logger := logging.NewNoopLogger() blobStore := inmem.NewBlobStore() - cst, err := coremock.MakeChainDataMock(numOperators) + cst, err := coremock.MakeChainDataMock(map[uint8]int{ + 0: numOperators, + 1: numOperators, + 2: numOperators, + }) assert.Nil(t, err) p, err := makeTestProver() assert.Nil(t, err) @@ -64,7 +68,11 @@ func createEncodingStreamer(t *testing.T, initialBlockNumber uint, batchThreshol func TestEncodingQueueLimit(t *testing.T) { logger := logging.NewNoopLogger() blobStore := inmem.NewBlobStore() - cst, err := coremock.MakeChainDataMock(numOperators) + cst, err := coremock.MakeChainDataMock(map[uint8]int{ + 0: numOperators, + 1: numOperators, + 2: numOperators, + }) assert.Nil(t, err) encoderClient := mock.NewMockEncoderClient() encoderClient.On("EncodeBlob", tmock.Anything, tmock.Anything, tmock.Anything).Return(nil, nil, nil) @@ -290,7 +298,11 @@ func TestStreamingEncoding(t *testing.T) { func TestEncodingFailure(t *testing.T) { logger := logging.NewNoopLogger() blobStore := inmem.NewBlobStore() - cst, err := coremock.MakeChainDataMock(numOperators) + cst, err := coremock.MakeChainDataMock(map[uint8]int{ + 0: numOperators, + 1: numOperators, + 2: numOperators, + }) assert.Nil(t, err) encoderClient := mock.NewMockEncoderClient() asgn := &core.StdAssignmentCoordinator{} diff --git a/disperser/dataapi/server_test.go b/disperser/dataapi/server_test.go index 6bf3ed15a1..ffb8aae0af 100644 --- a/disperser/dataapi/server_test.go +++ b/disperser/dataapi/server_test.go @@ -54,8 +54,12 @@ var ( config = dataapi.Config{ServerMode: "test", SocketAddr: ":8080", AllowOrigins: []string{"*"}, DisperserHostname: "localhost:32007", ChurnerHostname: "localhost:32009"} - mockTx = &coremock.MockTransactor{} - mockChainState, _ = coremock.MakeChainDataMock(core.OperatorIndex(1)) + mockTx = &coremock.MockTransactor{} + mockChainState, _ = coremock.MakeChainDataMock(map[uint8]int{ + 0: 1, + 1: 1, + 2: 1, + }) testDataApiServer = dataapi.NewServer(config, blobstore, prometheusClient, subgraphClient, mockTx, mockChainState, mockLogger, dataapi.NewMetrics(nil, "9001", mockLogger), &MockGRPCConnection{}, nil, nil) expectedBatchHeaderHash = [32]byte{1, 2, 3} expectedBlobIndex = uint32(1) diff --git a/disperser/encoder/server_test.go b/disperser/encoder/server_test.go index 1d047a462e..94138310b7 100644 --- a/disperser/encoder/server_test.go +++ b/disperser/encoder/server_test.go @@ -74,7 +74,11 @@ func getTestData() (core.Blob, encoding.EncodingParams) { Data: codec.ConvertByPaddingEmptyByte(gettysburgAddressBytes), } - indexedChainState, _ := coremock.MakeChainDataMock(core.OperatorIndex(10)) + indexedChainState, _ := coremock.MakeChainDataMock(map[uint8]int{ + 0: 10, + 1: 10, + 2: 10, + }) operatorState, err := indexedChainState.GetOperatorState(context.Background(), uint(0), []core.QuorumID{quorumID}) if err != nil { log.Fatalf("failed to get operator state: %s", err) diff --git a/node/grpc/server_test.go b/node/grpc/server_test.go index e5b198d54f..39d645a85f 100644 --- a/node/grpc/server_test.go +++ b/node/grpc/server_test.go @@ -40,7 +40,11 @@ var ( ) func TestMain(m *testing.M) { - chainState, _ = core_mock.MakeChainDataMock(core.OperatorIndex(4)) + chainState, _ = core_mock.MakeChainDataMock(map[uint8]int{ + 0: 4, + 1: 4, + 2: 4, + }) os.Exit(m.Run()) } @@ -122,7 +126,11 @@ func newTestServer(t *testing.T, mockValidator bool) *grpc.Server { asn := &core.StdAssignmentCoordinator{} - cst, err := core_mock.MakeChainDataMock(core.OperatorIndex(10)) + cst, err := core_mock.MakeChainDataMock(map[uint8]int{ + 0: 10, + 1: 10, + 2: 10, + }) if err != nil { panic("failed to create test encoder") } diff --git a/retriever/server_test.go b/retriever/server_test.go index 2b39b3316f..dcb48cc24c 100644 --- a/retriever/server_test.go +++ b/retriever/server_test.go @@ -62,7 +62,11 @@ func newTestServer(t *testing.T) *retriever.Server { logger := logging.NewNoopLogger() - indexedChainState, err = coremock.MakeChainDataMock(core.OperatorIndex(numOperators)) + indexedChainState, err = coremock.MakeChainDataMock(map[uint8]int{ + 0: numOperators, + 1: numOperators, + 2: numOperators, + }) if err != nil { log.Fatalf("failed to create new mocked chain data: %s", err) } diff --git a/test/integration_test.go b/test/integration_test.go index bc3b41a807..0a7a13a7ec 100644 --- a/test/integration_test.go +++ b/test/integration_test.go @@ -354,7 +354,11 @@ func TestDispersalAndRetrieval(t *testing.T) { } ctx := peer.NewContext(context.Background(), p) - cst, err := coremock.MakeChainDataMock(numOperators) + cst, err := coremock.MakeChainDataMock(map[uint8]int{ + 0: numOperators, + 1: numOperators, + 2: numOperators, + }) assert.NoError(t, err) cst.On("GetCurrentBlockNumber").Return(uint(10), nil)