Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ func (k msgServer) CreateDevshardEscrow(goCtx context.Context, msg *types.MsgCre

ep := k.GetDevshardEscrowParams(goCtx)

// Enforce the devshard kill switch: when requests are disabled, refuse to lock
// any new funds. Without this check the Guardian-gated kill switch only stops
// off-chain hosts from serving while the chain keeps accepting escrows.
if !ep.DevshardRequestsEnabled {
return nil, fmt.Errorf("devshard requests are currently disabled")
}

if msg.Amount < ep.MinAmount || msg.Amount > ep.MaxAmount {
return nil, fmt.Errorf("escrow amount %d out of range [%d, %d]", msg.Amount, ep.MinAmount, ep.MaxAmount)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ func TestCreateDevshardEscrow_ParamsOverrideDefaults(t *testing.T) {
AllowedCreatorAddresses: nil, // no restriction
TokenPrice: types.DefaultDevshardTokenPrice,
MaxNonce: types.DefaultDevshardMaxNonce,
DevshardRequestsEnabled: true,
}
require.NoError(t, k.SetParams(ctx, params))

Expand Down Expand Up @@ -293,3 +294,36 @@ func TestCreateDevshardEscrow_ModelGroupMustExist(t *testing.T) {
require.Error(t, err)
require.Contains(t, err.Error(), "failed to get epoch group for model")
}

func TestCreateDevshardEscrow_RequestsDisabledBlocks(t *testing.T) {
k, ms, ctx, _ := setupDevshardEscrowTest(t)

setupEpochGroupForDevshard(ctx, k, 5, testDevshardModelID, makeDevshardAddrs(1, 20))

creator := sdk.AccAddress(make([]byte, 20))
creator[0] = 0xFF

// Kill switch off: allowlist permits everyone, but requests are disabled.
params, err := k.GetParams(ctx)
require.NoError(t, err)
params.DevshardEscrowParams = &types.DevshardEscrowParams{
MinAmount: types.DefaultDevshardEscrowMinAmount,
MaxAmount: types.DefaultDevshardEscrowMaxAmount,
MaxEscrowsPerEpoch: types.DefaultDevshardMaxEscrowsPerEpoch,
GroupSize: types.DefaultDevshardGroupSize,
AllowedCreatorAddresses: nil,
TokenPrice: types.DefaultDevshardTokenPrice,
MaxNonce: types.DefaultDevshardMaxNonce,
DevshardRequestsEnabled: false,
}
require.NoError(t, k.SetParams(ctx, params))

// No bank mock is registered: the handler must reject before locking funds.
_, err = ms.CreateDevshardEscrow(ctx, &types.MsgCreateDevshardEscrow{
Creator: creator.String(),
Amount: 7_000_000_000,
ModelId: testDevshardModelID,
})
require.Error(t, err)
require.Contains(t, err.Error(), "devshard requests are currently disabled")
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ func (k msgServer) SettleDevshardEscrow(goCtx context.Context, msg *types.MsgSet
if devshardParams == nil {
return nil, fmt.Errorf("devshard escrow params not configured")
}
// Enforce the devshard kill switch: when requests are disabled, no escrow may be
// settled. This keeps funds frozen in place during an incident instead of letting
// a (possibly crafted) settlement drain the module while the switch is off.
if !devshardParams.DevshardRequestsEnabled {
return nil, fmt.Errorf("devshard requests are currently disabled")
}
if err := VerifyDevshardSettlement(escrow, msg, devshardParams.MaxNonce, warmKeyChecker); err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -642,3 +642,43 @@ func TestSettleDevshardEscrow_AllowlistBlocks(t *testing.T) {
require.Error(t, err)
require.Contains(t, err.Error(), "address is not allowed to create devshard escrows")
}

func TestSettleDevshardEscrow_RequestsDisabledBlocks(t *testing.T) {
k, ms, ctx, _ := setupDevshardEscrowTest(t)
sdk.GetConfig().SetBech32PrefixForAccount("gonka", "gonka")

creator := sdk.AccAddress(make([]byte, 20))
creator[0] = 0xCC
escrow := types.DevshardEscrow{
Id: 1,
Creator: creator.String(),
Amount: 7_000_000_000,
Slots: make([]string, keeper.DevshardGroupSize),
Settled: false,
}
_, err := k.StoreDevshardEscrow(ctx, &escrow, 1)
require.NoError(t, err)

// Kill switch off: allowlist permits everyone, but requests are disabled.
params, err := k.GetParams(ctx)
require.NoError(t, err)
params.DevshardEscrowParams = &types.DevshardEscrowParams{
MinAmount: types.DefaultDevshardEscrowMinAmount,
MaxAmount: types.DefaultDevshardEscrowMaxAmount,
MaxEscrowsPerEpoch: types.DefaultDevshardMaxEscrowsPerEpoch,
GroupSize: types.DefaultDevshardGroupSize,
AllowedCreatorAddresses: nil,
TokenPrice: types.DefaultDevshardTokenPrice,
MaxNonce: types.DefaultDevshardMaxNonce,
DevshardRequestsEnabled: false,
}
require.NoError(t, k.SetParams(ctx, params))

// No bank mock is registered: the handler must reject before moving funds.
_, err = ms.SettleDevshardEscrow(ctx, &types.MsgSettleDevshardEscrow{
Settler: creator.String(),
EscrowId: 1,
})
require.Error(t, err)
require.Contains(t, err.Error(), "devshard requests are currently disabled")
}
Loading