-
Notifications
You must be signed in to change notification settings - Fork 4.9k
budget as separate contract and system call contract #1189
Conversation
I see Instruction still depends on Budget. Does it need to? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see Instruction still depends on Budget.
Instruction should eventually be an implementation detail of Budget
src/transaction.rs
Outdated
@@ -88,6 +25,7 @@ pub struct Transaction { | |||
/// In the future which key pays the fee and which keys have signatures would be configurable. | |||
/// * keys[1] - Typically this is the contract context or the recipient of the tokens | |||
pub keys: Vec<Pubkey>, | |||
pub contract_id: u64, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want this be a PubKey? As u64
we need a central registry
src/bank.rs
Outdated
if let Some(id) = contract_id { | ||
accounts[1].contract_id = id; | ||
} | ||
accounts[1].userdata = vec![0; space as usize]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we only permit userdata if there's a contract_id
?
src/bank.rs
Outdated
pub fn get_balance(&self, pubkey: &Pubkey) -> i64 { | ||
self.get_account(pubkey) | ||
.map(|x| Self::get_balance_of_budget_payment_plan(&x)) | ||
.map(|x| budget::get_balance(&x)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should check that this Account
is a budget account first right?
src/bank.rs
Outdated
#[derive(Serialize, Deserialize, Debug, Clone, Default)] | ||
pub struct Account { | ||
/// tokens in the account | ||
pub tokens: i64, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we permit negative tokens?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I still like to believe we'll be able to coalesce transactions from the right to trivialize rollback. I hijacked that top bit to keep the dream alive.
src/budget.rs
Outdated
/// * accounts[1] - The contract context. Once the contract has been completed, the tokens can | ||
/// be spent from this account . | ||
pub fn process_transaction(tx: &Transaction, accounts: &mut [Account]) -> () { | ||
let instruction = deserialize(&tx.userdata).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
worthwhile assert there are two accounts here? I guess it'll panic in apply_debits_to_budget_state
or apply_credits_to_budget_state
if not...
|
src/budget.rs
Outdated
last_error: Option<BudgetError>, | ||
} | ||
|
||
pub const BUDGET_STATE_CONTRACT_ID: [u8; 32] = [0u8; 32]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wait, this is the same value as SYSTEM_CALL_CONTRACT_ID
. How about:
- nothing = 0
- SYSTEM_CALL_CONTRACT_ID = 1
- BUDGET_STATE_CONTRACT_ID = 2
src/system.rs
Outdated
use transaction::Transaction; | ||
|
||
#[derive(Serialize, Deserialize, Debug, Clone)] | ||
pub enum System { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be called SystemContract to align with BudgetContract?
@mvines here is a robust transfer on date that covers trying to pay out to the wrong key |
* contract check_id methods * system call contract * verify contract execution rules * move system into its own file * allocate before transfer for budget * store error in budget context * budget contract and tests without bank * moved budget of of bank
3d7d0f9
to
f07f685
Compare
@@ -0,0 +1,68 @@ | |||
use budget::Budget; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instruction.rs is really just an implementation detail of budget, so (maybe later) this file could merge into budget.rs right?
@@ -594,7 +555,7 @@ impl Bank { | |||
{ | |||
let tx = &entry1.transactions[0]; | |||
let instruction = tx.instruction(); | |||
let deposit = if let Instruction::NewContract(contract) = instruction { | |||
let deposit = if let Some(Instruction::NewContract(contract)) = instruction { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't we pass tx
through process_transaction()
here instead of hard coding a Budget Contract instruction?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mvines maybe, not sure. its outside the scope of moving budget as a separate contract
needs a wool update |
This looks good enough to land IMO, |
…na-labs#1189) Bumps [rollup](https://github.com/rollup/rollup) from 2.38.4 to 2.38.5. - [Release notes](https://github.com/rollup/rollup/releases) - [Changelog](https://github.com/rollup/rollup/blob/master/CHANGELOG.md) - [Commits](rollup/rollup@v2.38.4...v2.38.5) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…port of solana-labs#1189) (solana-labs#1208) RPC: fix numNonVoteTransactions in getPerformanceSamples (solana-labs#1189) (cherry picked from commit 3f6c567) Co-authored-by: Justin Starry <justin@anza.xyz>
WIP, part of #953