Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have SubtensorModule::TotalIssuance track extrinsic fees #816

Open
camfairchild opened this issue Sep 17, 2024 · 2 comments
Open

Have SubtensorModule::TotalIssuance track extrinsic fees #816

camfairchild opened this issue Sep 17, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@camfairchild
Copy link
Contributor

Describe the bug

The pallet_subtensor::migrations::migrate_init_total_issuance::initialise_total_issuance migration is seemingly running every time there is a runtime upgrade. Also running every upgrade is a try_state check for the total issuance trackers, to make sure they are summing to the right values.

However, because the migration runs first, we can never reach a state where the try_state check fails.

Removing the migration run appears to create a fail-state for the try_state check, meaning some difference in the balances pallet TotalIssuance is differing from what we are tracking with the Subtensor pallet TotalIssuance.

My first assumption is the extrinsic fees and/or the balances pallet's account kill, where it burns the remainder of the balance below the existential deposit.

To Reproduce

  1. Remove call to run migration for pallet_subtensor::migrations::migrate_init_total_issuance::initialise_total_issuance
  2. Run a try-runtime check locally
  3. Error: ERROR runtime::frame-support] ❌ "SubtensorModule" try_state checks failed: Other("TotalIssuance accounting discrepancy")

Expected behavior

I would expect the total issuance to not differ between the storage values, as the try_state expects.

Screenshots

No response

Environment

Subtensor 201

Additional context

No response

@camfairchild camfairchild added the bug Something isn't working label Sep 17, 2024
@orriin
Copy link
Contributor

orriin commented Sep 20, 2024

It does handle transaction fees:

/// Deduct the transaction fee from the Subtensor Pallet TotalIssuance when dropping the transaction
/// fee.
pub struct TransactionFeeHandler;
impl OnUnbalanced<NegativeImbalance<Runtime>> for TransactionFeeHandler {
fn on_nonzero_unbalanced(credit: NegativeImbalance<Runtime>) {
let ti_before = pallet_subtensor::TotalIssuance::<Runtime>::get();
pallet_subtensor::TotalIssuance::<Runtime>::put(ti_before.saturating_sub(credit.peek()));
drop(credit);
}
}
impl pallet_transaction_payment::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
//type TransactionByteFee = TransactionByteFee;
type OnChargeTransaction = CurrencyAdapter<Balances, TransactionFeeHandler>;

This rounding issue is tiny (~20 rao) due to floating point arithmetic issues.

@camfairchild
Copy link
Contributor Author

It does handle transaction fees:

/// Deduct the transaction fee from the Subtensor Pallet TotalIssuance when dropping the transaction
/// fee.
pub struct TransactionFeeHandler;
impl OnUnbalanced<NegativeImbalance<Runtime>> for TransactionFeeHandler {
fn on_nonzero_unbalanced(credit: NegativeImbalance<Runtime>) {
let ti_before = pallet_subtensor::TotalIssuance::<Runtime>::get();
pallet_subtensor::TotalIssuance::<Runtime>::put(ti_before.saturating_sub(credit.peek()));
drop(credit);
}
}
impl pallet_transaction_payment::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
//type TransactionByteFee = TransactionByteFee;
type OnChargeTransaction = CurrencyAdapter<Balances, TransactionFeeHandler>;

This rounding issue is tiny (~20 rao) due to floating point arithmetic issues.

does this hook on account kill sweeps?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants