diff --git a/node/node.go b/node/node.go index 2805ba746..8672eac21 100644 --- a/node/node.go +++ b/node/node.go @@ -698,6 +698,10 @@ func (n *Node) AbortBlockExecution(height int64, txIDs []types.Hash) error { return n.ce.CancelBlockExecution(height, txIDs) } +func (n *Node) Role() types.Role { + return n.ce.Role() +} + var RequiredStreamProtocols = []protocol.ID{ ProtocolIDDiscover, ProtocolIDTx, diff --git a/node/services/jsonrpc/adminsvc/service.go b/node/services/jsonrpc/adminsvc/service.go index 8e1464a73..6fdfdec4a 100644 --- a/node/services/jsonrpc/adminsvc/service.go +++ b/node/services/jsonrpc/adminsvc/service.go @@ -16,6 +16,7 @@ import ( types "github.com/kwilteam/kwil-db/core/types/admin" "github.com/kwilteam/kwil-db/extensions/resolutions" rpcserver "github.com/kwilteam/kwil-db/node/services/jsonrpc" + ntypes "github.com/kwilteam/kwil-db/node/types" "github.com/kwilteam/kwil-db/node/types/sql" "github.com/kwilteam/kwil-db/node/voting" "github.com/kwilteam/kwil-db/version" @@ -27,6 +28,7 @@ type Node interface { Status(context.Context) (*types.Status, error) Peers(context.Context) ([]*types.PeerInfo, error) BroadcastTx(ctx context.Context, tx *ktypes.Transaction, sync uint8) (*ktypes.ResultBroadcastTx, error) + Role() ntypes.Role AbortBlockExecution(height int64, txIDs []ktypes.Hash) error } @@ -598,6 +600,10 @@ func (svc *Service) BlockExecStatus(ctx context.Context, req *adminjson.BlockExe } func (svc *Service) AbortBlockExecution(ctx context.Context, req *adminjson.AbortBlockExecRequest) (*adminjson.AbortBlockExecResponse, *jsonrpc.Error) { + if svc.blockchain.Role() != ntypes.RoleLeader { + return nil, jsonrpc.NewError(jsonrpc.ErrorInternal, "only the leader can abort block execution", nil) + } + txIds := make([]ktypes.Hash, len(req.Txs)) for i, tx := range req.Txs { txId, err := ktypes.NewHashFromString(tx)