Skip to content

Commit 1f4bcd4

Browse files
authored
Merge pull request #3202 from opentensor/bug/roman/add_stake
[v10] Avoid negative balance to `add_stake`
2 parents fb887f3 + 73d781e commit 1f4bcd4

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

bittensor/core/extrinsics/asyncex/staking.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ async def add_stake_extrinsic(
8989
subtensor.get_existential_deposit(block_hash=block_hash),
9090
)
9191

92+
# Leave existential balance to keep key alive.
93+
if old_balance <= existential_deposit:
94+
return ExtrinsicResponse(
95+
False,
96+
f"Balance ({old_balance}) is not enough to cover existential deposit `{existential_deposit}`.",
97+
).with_log()
98+
9299
# Leave existential balance to keep key alive.
93100
if amount > old_balance - existential_deposit:
94101
# If we are staking all, we need to leave at least the existential deposit.

bittensor/core/extrinsics/staking.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ def add_stake_extrinsic(
8686
)
8787
existential_deposit = subtensor.get_existential_deposit(block=block)
8888

89+
# Leave existential balance to keep key alive.
90+
if old_balance <= existential_deposit:
91+
return ExtrinsicResponse(
92+
False,
93+
f"Balance ({old_balance}) is not enough to cover existential deposit `{existential_deposit}`.",
94+
).with_log()
95+
8996
# Leave existential balance to keep key alive.
9097
if amount > old_balance - existential_deposit:
9198
# If we are staking all, we need to leave at least the existential deposit.

0 commit comments

Comments
 (0)