From 5c9d2183a05943ae6dd21bf19b51a1184c26f726 Mon Sep 17 00:00:00 2001 From: Ian Shim Date: Wed, 17 Jan 2024 23:57:09 -0800 Subject: [PATCH] node err logging --- clients/tests/retrieval_client_test.go | 2 +- core/aggregation.go | 2 +- core/assignment.go | 11 ++++++++--- core/attestation.go | 2 +- core/indexer/operator_sockets_filterer.go | 2 +- core/mock/validator.go | 1 - core/thegraph/state.go | 4 ++-- core/thegraph/state_test.go | 2 +- core/validator.go | 17 ++++++++--------- 9 files changed, 23 insertions(+), 20 deletions(-) diff --git a/clients/tests/retrieval_client_test.go b/clients/tests/retrieval_client_test.go index d62d190b4..86629cec8 100644 --- a/clients/tests/retrieval_client_test.go +++ b/clients/tests/retrieval_client_test.go @@ -194,7 +194,7 @@ func setup(t *testing.T) { } func mustMakeOpertatorPubKeysPair(t *testing.T) *coreindexer.OperatorPubKeys { - operators := make(map[[32]byte]coreindexer.OperatorPubKeysPair, len(operatorState.Operators)) + operators := make(map[core.OperatorID]coreindexer.OperatorPubKeysPair, len(operatorState.Operators)) for operatorId := range operatorState.Operators[0] { keyPair, err := core.GenRandomBlsKeys() if err != nil { diff --git a/core/aggregation.go b/core/aggregation.go index 7ba3cce28..acd7694cc 100644 --- a/core/aggregation.go +++ b/core/aggregation.go @@ -102,7 +102,7 @@ func (a *StdSignatureAggregator) AggregateSignatures(ctx context.Context, state for numReply := 0; numReply < numOperators; numReply++ { var err error r := <-messageChan - operatorIDHex := hexutil.Encode(r.Operator[:]) + operatorIDHex := r.Operator.Hex() operatorAddr, ok := a.OperatorAddresses.Get(r.Operator) if !ok && a.Transactor != nil { operatorAddr, err = a.Transactor.OperatorIDToAddress(ctx, r.Operator) diff --git a/core/assignment.go b/core/assignment.go index 679d00c6b..3b71ace2b 100644 --- a/core/assignment.go +++ b/core/assignment.go @@ -1,6 +1,7 @@ package core import ( + "encoding/hex" "errors" "fmt" "math" @@ -28,7 +29,11 @@ var ( // Assignment -type OperatorID = [32]byte +type OperatorID [32]byte + +func (id OperatorID) Hex() string { + return hex.EncodeToString(id[:]) +} type OperatorIndex = uint @@ -156,7 +161,7 @@ func (c *StdAssignmentCoordinator) ValidateChunkLength(state *OperatorState, blo // Check that the chunk length meets the minimum requirement if info.ChunkLength < MinChunkLength { - return false, ErrChunkLengthTooSmall + return false, fmt.Errorf("%w: chunk length: %d, min chunk length: %d", ErrChunkLengthTooSmall, info.ChunkLength, MinChunkLength) } // Get minimum stake amont @@ -183,7 +188,7 @@ func (c *StdAssignmentCoordinator) ValidateChunkLength(state *OperatorState, blo maxChunkLength = uint(nextPowerOf2(uint64(maxChunkLength))) if info.ChunkLength > maxChunkLength { - return false, ErrChunkLengthTooLarge + return false, fmt.Errorf("%w: chunk length: %d, max chunk length: %d", ErrChunkLengthTooLarge, info.ChunkLength, maxChunkLength) } } diff --git a/core/attestation.go b/core/attestation.go index 461e49703..669a9023e 100644 --- a/core/attestation.go +++ b/core/attestation.go @@ -84,7 +84,7 @@ func (s *Signature) Verify(pubkey *G2Point, message [32]byte) bool { func (p *G1Point) GetOperatorID() OperatorID { x := p.X.BigInt(new(big.Int)) y := p.Y.BigInt(new(big.Int)) - return crypto.Keccak256Hash(append(math.U256Bytes(x), math.U256Bytes(y)...)) + return OperatorID(crypto.Keccak256Hash(append(math.U256Bytes(x), math.U256Bytes(y)...))) } type PrivateKey = fr.Element diff --git a/core/indexer/operator_sockets_filterer.go b/core/indexer/operator_sockets_filterer.go index d60f04f81..d1809bc3b 100644 --- a/core/indexer/operator_sockets_filterer.go +++ b/core/indexer/operator_sockets_filterer.go @@ -114,7 +114,7 @@ func (f *operatorSocketsFilterer) WatchOperatorSocketUpdate(ctx context.Context, } sink := make(chan *blsregcoord.ContractBLSRegistryCoordinatorWithIndicesOperatorSocketUpdate) - operatorID := []core.OperatorID{operatorId} + operatorID := [][32]byte{operatorId} _, err = filterer.WatchOperatorSocketUpdate(&bind.WatchOpts{Context: ctx}, sink, operatorID) if err != nil { return nil, err diff --git a/core/mock/validator.go b/core/mock/validator.go index c80610e3a..ac11b223a 100644 --- a/core/mock/validator.go +++ b/core/mock/validator.go @@ -10,7 +10,6 @@ import ( var ( ErrChunkLengthMismatch = errors.New("chunk length mismatch") - ErrInvalidHeader = errors.New("invalid header") ) // MockChunkValidator is a mock implementation of ChunkValidator diff --git a/core/thegraph/state.go b/core/thegraph/state.go index 430f5d11a..f777e1172 100644 --- a/core/thegraph/state.go +++ b/core/thegraph/state.go @@ -144,7 +144,7 @@ func (ics *indexedChainState) GetIndexedOperatorInfoByOperatorId(ctx context.Con var ( query QueryOperatorByIdGql variables = map[string]any{ - "id": graphql.String(fmt.Sprintf("0x%s", hex.EncodeToString(operatorId[:]))), + "id": graphql.String(fmt.Sprintf("0x%s", operatorId.Hex())), } ) err := ics.querier.Query(context.Background(), &query, variables) @@ -235,7 +235,7 @@ func (ics *indexedChainState) getRegisteredIndexedOperatorInfo(ctx context.Conte return nil, err } - operators := make(map[[32]byte]*core.IndexedOperatorInfo, len(operatorsGql)) + operators := make(map[core.OperatorID]*core.IndexedOperatorInfo, len(operatorsGql)) for i := range operatorsGql { operator := operatorsGql[i] operatorIndexedInfo, err := convertIndexedOperatorInfoGqlToIndexedOperatorInfo(&operator) diff --git a/core/thegraph/state_test.go b/core/thegraph/state_test.go index 246132e68..c78d1134a 100644 --- a/core/thegraph/state_test.go +++ b/core/thegraph/state_test.go @@ -146,7 +146,7 @@ func TestIndexedChainState_GetIndexedOperatorInfoByOperatorId(t *testing.T) { assert.NoError(t, err) opID := ethcomm.HexToHash("0x3eb7d5df61c48ec2718d8c8ad52304effc970ae92f19138e032dae07b7c0d629") - info, err := cs.GetIndexedOperatorInfoByOperatorId(context.Background(), opID, uint32(headerNum)) + info, err := cs.GetIndexedOperatorInfoByOperatorId(context.Background(), core.OperatorID(opID.Bytes()), uint32(headerNum)) assert.NoError(t, err) assert.Equal(t, "3336192159512049190945679273141887248666932624338963482128432381981287252980", info.PubkeyG1.X.String()) assert.Equal(t, "15195175002875833468883745675063986308012687914999552116603423331534089122704", info.PubkeyG1.Y.String()) diff --git a/core/validator.go b/core/validator.go index 5a52cf962..806feeeda 100644 --- a/core/validator.go +++ b/core/validator.go @@ -9,7 +9,6 @@ import ( var ( ErrChunkLengthMismatch = errors.New("chunk length mismatch") - ErrInvalidHeader = errors.New("invalid header") ErrBlobQuorumSkip = errors.New("blob skipped for a quorum before verification") ) @@ -38,12 +37,12 @@ func NewChunkValidator(enc Encoder, asgn AssignmentCoordinator, cst ChainState, func (v *chunkValidator) validateBlobQuorum(quorumHeader *BlobQuorumInfo, blob *BlobMessage, operatorState *OperatorState) ([]*Chunk, *Assignment, *EncodingParams, error) { if quorumHeader.AdversaryThreshold >= quorumHeader.QuorumThreshold { - return nil, nil, nil, errors.New("invalid header: quorum threshold does not exceed adversary threshold") + return nil, nil, nil, fmt.Errorf("invalid header: quorum threshold (%d) does not exceed adversary threshold (%d)", quorumHeader.QuorumThreshold, quorumHeader.AdversaryThreshold) } // Check if the operator is a member of the quorum if _, ok := operatorState.Operators[quorumHeader.QuorumID]; !ok { - return nil, nil, nil, ErrBlobQuorumSkip + return nil, nil, nil, fmt.Errorf("%w: operator %s is not a member of quorum %d", ErrBlobQuorumSkip, v.operatorID.Hex(), quorumHeader.QuorumID) } // Get the assignments for the quorum @@ -54,10 +53,10 @@ func (v *chunkValidator) validateBlobQuorum(quorumHeader *BlobQuorumInfo, blob * // Validate the number of chunks if assignment.NumChunks == 0 { - return nil, nil, nil, ErrBlobQuorumSkip + return nil, nil, nil, fmt.Errorf("%w: operator %s has no chunks in quorum %d", ErrBlobQuorumSkip, v.operatorID.Hex(), quorumHeader.QuorumID) } if assignment.NumChunks != uint(len(blob.Bundles[quorumHeader.QuorumID])) { - return nil, nil, nil, errors.New("number of chunks does not match assignment") + return nil, nil, nil, fmt.Errorf("number of chunks (%d) does not match assignment (%d)", len(blob.Bundles[quorumHeader.QuorumID]), assignment.NumChunks) } // Validate the chunkLength against the quorum and adversary threshold parameters @@ -70,7 +69,7 @@ func (v *chunkValidator) validateBlobQuorum(quorumHeader *BlobQuorumInfo, blob * chunks := blob.Bundles[quorumHeader.QuorumID] for _, chunk := range chunks { if uint(chunk.Length()) != quorumHeader.ChunkLength { - return nil, nil, nil, ErrChunkLengthMismatch + return nil, nil, nil, fmt.Errorf("%w: chunk length (%d) does not match quorum header (%d)", ErrChunkLengthMismatch, chunk.Length(), quorumHeader.ChunkLength) } } @@ -81,7 +80,7 @@ func (v *chunkValidator) validateBlobQuorum(quorumHeader *BlobQuorumInfo, blob * } if params.ChunkLength != quorumHeader.ChunkLength { - return nil, nil, nil, errors.New("invalid chunk length") + return nil, nil, nil, fmt.Errorf("%w: chunk length from encoding parameters (%d) does not match quorum header (%d)", ErrChunkLengthMismatch, params.ChunkLength, quorumHeader.ChunkLength) } return chunks, &assignment, ¶ms, nil @@ -89,7 +88,7 @@ func (v *chunkValidator) validateBlobQuorum(quorumHeader *BlobQuorumInfo, blob * func (v *chunkValidator) ValidateBlob(blob *BlobMessage, operatorState *OperatorState) error { if len(blob.Bundles) != len(blob.BlobHeader.QuorumInfos) { - return errors.New("number of bundles does not match number of quorums") + return fmt.Errorf("number of bundles (%d) does not match number of quorums (%d)", len(blob.Bundles), len(blob.BlobHeader.QuorumInfos)) } // Validate the blob length @@ -127,7 +126,7 @@ func (v *chunkValidator) ValidateBatch(blobs []*BlobMessage, operatorState *Oper for k, blob := range blobs { if len(blob.Bundles) != len(blob.BlobHeader.QuorumInfos) { - return errors.New("number of bundles does not match number of quorums") + return fmt.Errorf("number of bundles (%d) does not match number of quorums (%d)", len(blob.Bundles), len(blob.BlobHeader.QuorumInfos)) } // Saved for the blob length validation