Skip to content

Commit

Permalink
fix build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
illia-malachyn committed Feb 7, 2025
1 parent d6fb90a commit a09d085
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 33 deletions.
25 changes: 14 additions & 11 deletions admin/commands/storage/backfill_tx_error_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ var _ commands.AdminCommand = (*BackfillTxErrorMessagesCommand)(nil)
// backfillTxErrorMessagesRequest represents the input parameters for
// backfilling transaction error messages.
type backfillTxErrorMessagesRequest struct {
startHeight uint64 // Start height from which to begin backfilling.
endHeight uint64 // End height up to which backfilling is performed.
executionNodeIds flow.IdentitySkeletonList // List of execution node IDs to be used for backfilling.
startHeight uint64 // Start height from which to begin backfilling.
endHeight uint64 // End height up to which backfilling is performed.
executionNodeIds flow.IdentityList // List of execution node IDs to be used for backfilling.
}

// BackfillTxErrorMessagesCommand executes a command to backfill
Expand Down Expand Up @@ -55,8 +55,11 @@ func (b *BackfillTxErrorMessagesCommand) Validator(request *admin.CommandRequest

data := &backfillTxErrorMessagesRequest{}

rootHeight := b.state.Params().SealedRoot().Height
data.startHeight = rootHeight // Default value
root, err := b.state.Params().SealedRoot()
if err != nil {
return fmt.Errorf("could not get sealed root: %w", err)
}
data.startHeight = root.Height // Default value

sealed, err := b.state.Sealed().Head()
if err != nil {
Expand All @@ -78,11 +81,11 @@ func (b *BackfillTxErrorMessagesCommand) Validator(request *admin.CommandRequest
)
}

if startHeight < rootHeight {
if startHeight < root.Height {
return admin.NewInvalidAdminReqErrorf(
"'start-height' %d must not be less than root block %d",
startHeight,
rootHeight,
root.Height,
)
}

Expand Down Expand Up @@ -115,7 +118,7 @@ func (b *BackfillTxErrorMessagesCommand) Validator(request *admin.CommandRequest
)
}

identities, err := b.state.Final().Identities(filter.HasRole[flow.Identity](flow.RoleExecution))
identities, err := b.state.Final().Identities(filter.HasRole(flow.RoleExecution))
if err != nil {
return fmt.Errorf("failed to retreive execution IDs: %w", err)
}
Expand All @@ -128,7 +131,7 @@ func (b *BackfillTxErrorMessagesCommand) Validator(request *admin.CommandRequest
data.executionNodeIds = executionNodeIds
} else {
// in case no execution node ids provided, the command will use any valid execution node
data.executionNodeIds = identities.ToSkeleton()
data.executionNodeIds = identities
}

request.ValidatorData = data
Expand Down Expand Up @@ -169,7 +172,7 @@ func (b *BackfillTxErrorMessagesCommand) Handler(ctx context.Context, request *a
//
// Expected errors during normal operation:
// - admin.InvalidAdminReqParameterError - if execution-node-ids is empty or has an invalid format.
func (b *BackfillTxErrorMessagesCommand) parseExecutionNodeIds(executionNodeIdsIn interface{}, allIdentities flow.IdentityList) (flow.IdentitySkeletonList, error) {
func (b *BackfillTxErrorMessagesCommand) parseExecutionNodeIds(executionNodeIdsIn interface{}, allIdentities flow.IdentityList) (flow.IdentityList, error) {
var ids flow.IdentityList

switch executionNodeIds := executionNodeIdsIn.(type) {
Expand All @@ -193,5 +196,5 @@ func (b *BackfillTxErrorMessagesCommand) parseExecutionNodeIds(executionNodeIdsI
return nil, admin.NewInvalidAdminReqParameterError("execution-node-ids", "must be a list of strings", executionNodeIdsIn)
}

return ids.ToSkeleton(), nil
return ids, nil
}
40 changes: 18 additions & 22 deletions admin/commands/storage/backfill_tx_error_messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
accessmock "github.com/onflow/flow-go/engine/access/mock"
"github.com/onflow/flow-go/engine/access/rpc/backend"
connectionmock "github.com/onflow/flow-go/engine/access/rpc/connection/mock"
commonrpc "github.com/onflow/flow-go/engine/common/rpc"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/state/protocol"
"github.com/onflow/flow-go/state/protocol/invalid"
Expand Down Expand Up @@ -98,6 +97,9 @@ func (suite *BackfillTxErrorMessagesSuite) SetupTest() {
func() *flow.Header {
return suite.nodeRootBlock.Header
}, nil)
suite.params.On("SporkID").Return(unittest.IdentifierFixture(), nil)
suite.params.On("ProtocolVersion").Return(uint(1), nil)
suite.params.On("SporkRootBlockHeight").Return(uint64(0), nil)
suite.state.On("Params").Return(suite.params, nil).Maybe()

suite.snapshot = createSnapshot(suite.T(), suite.sealedBlock.Header)
Expand All @@ -117,42 +119,36 @@ func (suite *BackfillTxErrorMessagesSuite) SetupTest() {
// Mock the protocol snapshot to return fixed execution node IDs.
suite.allENIDs = unittest.IdentityListFixture(1, unittest.WithRole(flow.RoleExecution))
suite.snapshot.On("Identities", mock.Anything).Return(
func(flow.IdentityFilter[flow.Identity]) (flow.IdentityList, error) {
func(flow.IdentityFilter) (flow.IdentityList, error) {
return suite.allENIDs, nil
}, nil).Maybe()

// create a mock connection factory
suite.connFactory = connectionmock.NewConnectionFactory(suite.T())

executionNodeIdentitiesProvider := commonrpc.NewExecutionNodeIdentitiesProvider(
suite.log,
suite.state,
suite.receipts,
nil,
nil,
)

var err error
suite.backend, err = backend.New(backend.Params{
State: suite.state,
ExecutionReceipts: suite.receipts,
ConnFactory: suite.connFactory,
MaxHeightRange: backend.DefaultMaxHeightRange,
Log: suite.log,
SnapshotHistoryLimit: backend.DefaultSnapshotHistoryLimit,
Communicator: backend.NewNodeCommunicator(false),
ScriptExecutionMode: backend.IndexQueryModeExecutionNodesOnly,
TxResultQueryMode: backend.IndexQueryModeExecutionNodesOnly,
ChainID: flow.Testnet,
ExecNodeIdentitiesProvider: executionNodeIdentitiesProvider,
State: suite.state,
ExecutionReceipts: suite.receipts,
ConnFactory: suite.connFactory,
MaxHeightRange: backend.DefaultMaxHeightRange,
Log: suite.log,
SnapshotHistoryLimit: backend.DefaultSnapshotHistoryLimit,
Communicator: backend.NewNodeCommunicator(false),
ScriptExecutionMode: backend.IndexQueryModeExecutionNodesOnly,
TxResultQueryMode: backend.IndexQueryModeExecutionNodesOnly,
ChainID: flow.Testnet,
})
require.NoError(suite.T(), err)

suite.txResultErrorMessagesCore = tx_error_messages.NewTxErrorMessagesCore(
suite.log,
suite.state,
suite.backend,
suite.receipts,
suite.txErrorMessages,
executionNodeIdentitiesProvider,
nil,
nil,
)

suite.command = NewBackfillTxErrorMessagesCommand(
Expand Down

0 comments on commit a09d085

Please sign in to comment.