Skip to content

Commit

Permalink
only leader can abort block execution
Browse files Browse the repository at this point in the history
  • Loading branch information
charithabandi committed Dec 18, 2024
1 parent 2706f9d commit 3c37abe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions node/services/jsonrpc/adminsvc/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3c37abe

Please sign in to comment.