Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

budget as separate contract and system call contract #1189

Merged
merged 4 commits into from
Sep 17, 2018

Conversation

aeyakovenko
Copy link
Member

WIP, part of #953

  • move budget out of bank
  • create a system call contract that allocates the account userdata, and assigns account's to contracts

@aeyakovenko aeyakovenko added work in progress This isn't quite right yet noCI Suppress CI on this Pull Request labels Sep 11, 2018
@aeyakovenko aeyakovenko requested a review from mvines September 11, 2018 21:40
@garious
Copy link
Contributor

garious commented Sep 11, 2018

I see Instruction still depends on Budget. Does it need to?

Copy link
Contributor

@mvines mvines left a 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

@@ -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,
Copy link
Contributor

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];
Copy link
Contributor

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))
Copy link
Contributor

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,
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mvines @garious had the idea that we could have validators vote with a negative fee. so we are supporting the possibility of negative tokens.

Copy link
Contributor

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();
Copy link
Contributor

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...

@aeyakovenko
Copy link
Member Author

@mvines @garious any ideas on naming? budgetstate seems super lame :)

@mvines
Copy link
Contributor

mvines commented Sep 12, 2018

BudgetState seems fine to me for now.

src/budget.rs Outdated
last_error: Option<BudgetError>,
}

pub const BUDGET_STATE_CONTRACT_ID: [u8; 32] = [0u8; 32];
Copy link
Contributor

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 {
Copy link
Contributor

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?

@aeyakovenko
Copy link
Member Author

@mvines here is a robust transfer on date that covers trying to pay out to the wrong key
https://github.com/solana-labs/solana/pull/1189/files#diff-ea09cf31a8172005d63e915f6cc56ff7R268

* 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
@aeyakovenko aeyakovenko removed noCI Suppress CI on this Pull Request work in progress This isn't quite right yet labels Sep 17, 2018
@@ -0,0 +1,68 @@
use budget::Budget;
Copy link
Contributor

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 {
Copy link
Contributor

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?

Copy link
Member Author

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

@mvines mvines added this to the v0.9 Swamis milestone Sep 17, 2018
@aeyakovenko
Copy link
Member Author

needs a wool update

@mvines
Copy link
Contributor

mvines commented Sep 17, 2018

This looks good enough to land IMO, :shipit:

@aeyakovenko aeyakovenko merged commit 6ec0e42 into solana-labs:master Sep 17, 2018
@aeyakovenko aeyakovenko mentioned this pull request Sep 17, 2018
6 tasks
vkomenda pushed a commit to vkomenda/solana that referenced this pull request Aug 29, 2021
…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>
steviez pushed a commit to steviez/solana that referenced this pull request May 7, 2024
CriesofCarrots pushed a commit to CriesofCarrots/solana that referenced this pull request May 7, 2024
yihau pushed a commit that referenced this pull request May 14, 2024
…port of #1189) (#1208)

RPC: fix numNonVoteTransactions in getPerformanceSamples (#1189)

(cherry picked from commit 3f6c567)

Co-authored-by: Justin Starry <justin@anza.xyz>
yihau pushed a commit to yihau/solana that referenced this pull request May 15, 2024
…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>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants