diff --git a/clients/tests/retrieval_client_test.go b/clients/tests/retrieval_client_test.go index 7f5684f53a..369a0a5f96 100644 --- a/clients/tests/retrieval_client_test.go +++ b/clients/tests/retrieval_client_test.go @@ -70,12 +70,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 acd7694cc6..2f1182ce24 100644 --- a/core/aggregation.go +++ b/core/aggregation.go @@ -141,15 +141,13 @@ func (a *StdSignatureAggregator) AggregateSignatures(ctx context.Context, state a.Logger.Info("[AggregateSignatures] received signature from operator", "operatorID", operatorIDHex, "operatorAddress", operatorAddr, "socket", socket) - 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.Error("Operator not found in quorum", "operatorID", operatorIDHex, "operatorAddress", operatorAddr, "socket", socket) + a.Logger.Error("Operator not found in quorum", "operatorID", operatorIDHex, "operatorAddress", operatorAddr, "socket", socket, "quorumID", quorumID) continue } @@ -186,21 +184,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.Deserialize(quorumAggKey.Serialize()) 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 9b5c0e042f..315b602eb8 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,19 +90,19 @@ 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 9/10 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", @@ -111,14 +114,45 @@ func TestAggregateSignaturesStatus(t *testing.T) { }, adversaryCount: 2, expectedErr: nil, - meetsQuorum: false, + meetsQuorum: []bool{false}, + }, + { + name: "Fails when 9/10 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 9/10 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 e64df17c3a..5e6049f1dd 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.QuorumThreshold - 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) m := roundUpDivideBig(num, denom) diff --git a/core/assignment_test.go b/core/assignment_test.go index 74873bada2..887d83da09 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 1893ecf3f9..019eac80dc 100644 --- a/core/mock/state.go +++ b/core/mock/state.go @@ -2,6 +2,7 @@ package mock import ( "context" + "errors" "fmt" "math/big" @@ -12,10 +13,9 @@ import ( type ChainDataMock struct { mock.Mock - KeyPairs []*core.KeyPair - NumOperators core.OperatorIndex - - Stakes []int + KeyPairs map[core.OperatorID]*core.KeyPair + NumOperators uint8 + Stakes map[core.QuorumID]map[core.OperatorID]int } var _ core.ChainState = (*ChainDataMock)(nil) @@ -36,133 +36,153 @@ 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)) - - keyPairs := make([]*core.KeyPair, numOperators) - for ind := core.OperatorIndex(0); ind < numOperators; ind++ { - keyPair, err := core.GenRandomBlsKeys() - if err != nil { - return nil, err +func NewChainDataMock(stakes map[core.QuorumID]map[core.OperatorID]int) (*ChainDataMock, error) { + numOperators := 0 + keyPairs := make(map[core.OperatorID]*core.KeyPair) + for _, oprStakes := range stakes { + if len(oprStakes) > 255 { + return nil, errors.New("too many operators") + } + if len(oprStakes) > numOperators { + numOperators = len(oprStakes) + } + for opID := range oprStakes { + if _, ok := keyPairs[opID]; ok { + continue + } + keyPair, err := core.GenRandomBlsKeys() + if err != nil { + return nil, err + } + keyPairs[opID] = keyPair } - keyPairs[ind] = keyPair } return &ChainDataMock{ - NumOperators: numOperators, KeyPairs: keyPairs, + NumOperators: uint8(numOperators), 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 { +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) + } + } + 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 - - quorumStake := 0 - - for ind := core.OperatorIndex(0); ind < d.NumOperators; ind++ { - if ind == 0 { - key := d.KeyPairs[ind].GetPubKeyG1() - aggPubKey = key.Deserialize(key.Serialize()) - } else { - aggPubKey.Add(d.KeyPairs[ind].GetPubKeyG1()) + aggPubKeys := make(map[core.QuorumID]*core.G1Point) + for i := 0; i < int(d.NumOperators); i++ { + id := MakeOperatorId(i) + stake := 0 + for _, stakesByOp := range d.Stakes { + if s, ok := stakesByOp[id]; ok { + stake = s + break + } } - - 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(), + } + + stored := &core.OperatorInfo{ + Stake: big.NewInt(int64(stake)), + Index: uint(i), } 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) - } - 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: { + totals := make(map[core.QuorumID]*core.OperatorInfo) + for _, quorumID := range quorums { + stakesByOp := d.Stakes[quorumID] + quorumStake := 0 + for _, stake := range stakesByOp { + quorumStake += stake + } + totals[quorumID] = &core.OperatorInfo{ Stake: big.NewInt(int64(quorumStake)), - Index: d.NumOperators, - }, - } - - 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, - } + Index: uint(len(stakesByOp)), } } - 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 + operators := make(map[core.QuorumID]map[core.OperatorID]*core.OperatorInfo) + for _, quorumID := range quorums { + stakesByOp := d.Stakes[quorumID] + + quorumOperators := make(map[core.OperatorID]*core.OperatorInfo) + for oprID := range stakesByOp { + quorumOperators[oprID] = storedOperators[oprID] } + operators[quorumID] = quorumOperators } operatorState := &core.OperatorState{ @@ -171,14 +191,24 @@ func (d *ChainDataMock) GetTotalOperatorStateWithQuorums(ctx context.Context, bl BlockNumber: blockNumber, } + for quorumID, operatorsByID := range operators { + for opID := range operatorsByID { + if aggPubKeys[quorumID] == nil { + key := privateOperators[opID].KeyPair.GetPubKeyG1() + aggPubKeys[quorumID] = key.Deserialize(key.Serialize()) + } 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 +222,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 383613b90a..5343a8dd80 100644 --- a/core/test/core_test.go +++ b/core/test/core_test.go @@ -86,7 +86,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/disperser/batcher/batcher_test.go b/disperser/batcher/batcher_test.go index 5ce25c2381..7592dcfa44 100644 --- a/disperser/batcher/batcher_test.go +++ b/disperser/batcher/batcher_test.go @@ -74,7 +74,11 @@ func makeBatcher(t *testing.T) (*batcherComponents, *bat.Batcher, func() []time. assert.NoError(t, err) // 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), nil) asgn := &core.StdAssignmentCoordinator{} diff --git a/disperser/batcher/encoding_streamer_test.go b/disperser/batcher/encoding_streamer_test.go index 7dfdb35912..be584e3f40 100644 --- a/disperser/batcher/encoding_streamer_test.go +++ b/disperser/batcher/encoding_streamer_test.go @@ -39,7 +39,11 @@ type components struct { func createEncodingStreamer(t *testing.T, initialBlockNumber uint, batchThreshold uint64, streamerConfig batcher.StreamerConfig) (*batcher.EncodingStreamer, *components) { logger := &cmock.Logger{} 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) @@ -62,7 +66,11 @@ func createEncodingStreamer(t *testing.T, initialBlockNumber uint, batchThreshol func TestEncodingQueueLimit(t *testing.T) { logger := &cmock.Logger{} 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) @@ -288,7 +296,11 @@ func TestStreamingEncoding(t *testing.T) { func TestEncodingFailure(t *testing.T) { logger := &cmock.Logger{} 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 2cafffb85d..c0f4c2c470 100644 --- a/disperser/dataapi/server_test.go +++ b/disperser/dataapi/server_test.go @@ -50,8 +50,12 @@ var ( subgraphClient = dataapi.NewSubgraphClient(mockSubgraphApi, mockLogger) config = dataapi.Config{ServerMode: "test", SocketAddr: ":8080"} - 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)) expectedBatchHeaderHash = [32]byte{1, 2, 3} expectedBlobIndex = uint32(1) diff --git a/disperser/encoder/server_test.go b/disperser/encoder/server_test.go index 8a083cb060..b0feaa874a 100644 --- a/disperser/encoder/server_test.go +++ b/disperser/encoder/server_test.go @@ -73,7 +73,11 @@ func getTestData() (core.Blob, encoding.EncodingParams) { Data: 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 4bfbf0a7bb..45e1159773 100644 --- a/node/grpc/server_test.go +++ b/node/grpc/server_test.go @@ -39,7 +39,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()) } @@ -119,7 +123,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 2a864201f1..1259113d8e 100644 --- a/retriever/server_test.go +++ b/retriever/server_test.go @@ -61,7 +61,11 @@ func newTestServer(t *testing.T) *retriever.Server { logger := &commock.Logger{} - 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 fa154f87f1..29d40cbe42 100644 --- a/test/integration_test.go +++ b/test/integration_test.go @@ -353,7 +353,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)