Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
4775: Precursor for reserved delegator slots r=darthsiroftardis a=j-chmielewski

This is a minimal PR to make sure relevant breaking changes to data structures are in place for 2.0 / condor release. This allows us to avoid introducing breaking changes in the future release that includes the full implementation of the reserved delegator slots functionality.

Changes:
* added `ValidatorBid::reserved_slots` field to track number of reserved slots (defaulted to 0)
* added `add_reservations` and `cancel_reservations` auction contracts with stubbed implementations
* added `struct Reservation` to track reservations
* added `BidKind::Reservation(Box<Reservation>)` and `BidKindTag::Reservation` variants
* added `BidAddr::Reservation` and `BidAddrTag::Reservation` variants
* added `TransactionEntryPoint::{AddReservations, CancelReservations}` variants
* added auction costs for add/cancel reservations ops

Co-authored-by: Jacek Chmielewski <[email protected]>
  • Loading branch information
casperlabs-bors-ng[bot] and j-chmielewski authored Aug 15, 2024
2 parents d6b39e9 + f8bb26b commit 6416c72
Show file tree
Hide file tree
Showing 33 changed files with 690 additions and 33 deletions.
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions execution_engine/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,9 @@ where
{
return Err(ExecError::Revert(ApiError::InvalidDelegationAmountLimits));
}
let reserved_slots =
Self::try_get_named_argument(runtime_args, auction::ARG_RESERVED_SLOTS)?
.unwrap_or(0);

let result = runtime
.add_bid(
Expand All @@ -976,6 +979,7 @@ where
amount,
minimum_delegation_amount,
maximum_delegation_amount,
reserved_slots,
)
.map_err(Self::reverter)?;

Expand Down
8 changes: 4 additions & 4 deletions execution_engine_testing/tests/src/test/explorer/faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,10 +660,10 @@ fn faucet_costs() {
// This test will fail if execution costs vary. The expected costs should not be updated
// without understanding why the cost has changed. If the costs do change, it should be
// reflected in the "Costs by Entry Point" section of the faucet crate's README.md.
const EXPECTED_FAUCET_INSTALL_COST: u64 = 160_811_649_004;
const EXPECTED_FAUCET_SET_VARIABLES_COST: u64 = 135_357_070;
const EXPECTED_FAUCET_CALL_BY_INSTALLER_COST: u64 = 2_884_534_667;
const EXPECTED_FAUCET_CALL_BY_USER_COST: u64 = 2_623_240_446;
const EXPECTED_FAUCET_INSTALL_COST: u64 = 160_878_698_504;
const EXPECTED_FAUCET_SET_VARIABLES_COST: u64 = 135_355_310;
const EXPECTED_FAUCET_CALL_BY_INSTALLER_COST: u64 = 2_884_533_347;
const EXPECTED_FAUCET_CALL_BY_USER_COST: u64 = 2_623_236_926;

let installer_account = AccountHash::new([1u8; 32]);
let user_account: AccountHash = AccountHash::new([2u8; 32]);
Expand Down
4 changes: 3 additions & 1 deletion node/src/components/transaction_acceptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,9 @@ impl TransactionAcceptor {
| TransactionEntryPoint::Undelegate
| TransactionEntryPoint::Redelegate
| TransactionEntryPoint::ActivateBid
| TransactionEntryPoint::ChangeBidPublicKey => None,
| TransactionEntryPoint::ChangeBidPublicKey
| TransactionEntryPoint::AddReservations
| TransactionEntryPoint::CancelReservations => None,
},
};

Expand Down
2 changes: 2 additions & 0 deletions resources/local/chainspec.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ read_era_id = 10_000
activate_bid = 10_000
redelegate = 2_500_000_000
change_bid_public_key = 5_000_000_000
add_reservations = 2_500_000_000
cancel_reservations = 2_500_000_000

[system_costs.mint_costs]
mint = 2_500_000_000
Expand Down
2 changes: 2 additions & 0 deletions resources/production/chainspec.toml
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ read_era_id = 10_000
activate_bid = 10_000
redelegate = 2_500_000_000
change_bid_public_key = 5_000_000_000
add_reservations = 2_500_000_000
cancel_reservations = 2_500_000_000

[system_costs.mint_costs]
mint = 2_500_000_000
Expand Down
68 changes: 68 additions & 0 deletions resources/test/sse_data_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2053,6 +2053,20 @@
"enum": [
"ChangeBidPublicKey"
]
},
{
"description": "The `add_reservations` native entry point, used to add delegator to validator's reserve list",
"type": "string",
"enum": [
"AddReservations"
]
},
{
"description": "The `cancel_reservations` native entry point, used to remove delegator from validator's reserve list",
"type": "string",
"enum": [
"CancelReservations"
]
}
]
},
Expand Down Expand Up @@ -3234,6 +3248,19 @@
}
},
"additionalProperties": false
},
{
"description": "Reservation",
"type": "object",
"required": [
"Reservation"
],
"properties": {
"Reservation": {
"$ref": "#/definitions/Reservation"
}
},
"additionalProperties": false
}
]
},
Expand All @@ -3246,6 +3273,7 @@
"inactive",
"maximum_delegation_amount",
"minimum_delegation_amount",
"reserved_slots",
"staked_amount",
"validator_public_key"
],
Expand Down Expand Up @@ -3306,6 +3334,12 @@
"type": "integer",
"format": "uint64",
"minimum": 0.0
},
"reserved_slots": {
"description": "Slots reserved for specific delegators",
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
},
"additionalProperties": false
Expand Down Expand Up @@ -3382,6 +3416,40 @@
},
"additionalProperties": false
},
"Reservation": {
"description": "Represents a validator reserving a slot for specific delegator",
"type": "object",
"required": [
"delegation_rate",
"delegator_public_key",
"validator_public_key"
],
"properties": {
"delegator_public_key": {
"description": "Delegator public key",
"allOf": [
{
"$ref": "#/definitions/PublicKey"
}
]
},
"validator_public_key": {
"description": "Validator public key",
"allOf": [
{
"$ref": "#/definitions/PublicKey"
}
]
},
"delegation_rate": {
"description": "Individual delegation rate",
"type": "integer",
"format": "uint8",
"minimum": 0.0
}
},
"additionalProperties": false
},
"ExecutionResultV2": {
"description": "The result of executing a single transaction.",
"type": "object",
Expand Down
2 changes: 2 additions & 0 deletions resources/test/valid/0_9_0/chainspec.toml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ read_era_id = 10_000
activate_bid = 10_000
redelegate = 10_000
change_bid_public_key = 10_000
add_reservations = 2_500_000_000
cancel_reservations = 2_500_000_000

[system_costs.mint_costs]
mint = 2_500_000_000
Expand Down
2 changes: 2 additions & 0 deletions resources/test/valid/0_9_0_unordered/chainspec.toml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ read_era_id = 10_000
activate_bid = 10_000
redelegate = 10_000
change_bid_public_key = 10_000
add_reservations = 2_500_000_000
cancel_reservations = 2_500_000_000

[system_costs.mint_costs]
mint = 2_500_000_000
Expand Down
2 changes: 2 additions & 0 deletions resources/test/valid/1_0_0/chainspec.toml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ read_era_id = 10_000
activate_bid = 10_000
redelegate = 10_000
change_bid_public_key = 10_000
add_reservations = 2_500_000_000
cancel_reservations = 2_500_000_000

[system_costs.mint_costs]
mint = 2_500_000_000
Expand Down
7 changes: 7 additions & 0 deletions smart_contracts/contracts/client/add-bid/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ fn add_bid(
delegation_rate: auction::DelegationRate,
minimum_delegation_amount: Option<u64>,
maximum_delegation_amount: Option<u64>,
reserved_slots: Option<u32>,
) {
let contract_hash = system::get_auction();
let mut args = runtime_args! {
Expand All @@ -88,6 +89,9 @@ fn add_bid(
maximum_delegation_amount,
);
}
if let Some(reserved_slots) = reserved_slots {
let _ = args.insert(auction::ARG_RESERVED_SLOTS, reserved_slots);
}
runtime::call_contract::<U512>(contract_hash, auction::METHOD_ADD_BID, args);
}

Expand All @@ -100,15 +104,18 @@ pub extern "C" fn call() {
let public_key = runtime::get_named_arg(auction::ARG_PUBLIC_KEY);
let bond_amount = runtime::get_named_arg(auction::ARG_AMOUNT);
let delegation_rate = runtime::get_named_arg(auction::ARG_DELEGATION_RATE);

// Optional arguments
let minimum_delegation_amount = get_optional_named_args(auction::ARG_MINIMUM_DELEGATION_AMOUNT);
let maximum_delegation_amount = get_optional_named_args(auction::ARG_MAXIMUM_DELEGATION_AMOUNT);
let reserved_slots = get_optional_named_args(auction::ARG_RESERVED_SLOTS);

add_bid(
public_key,
bond_amount,
delegation_rate,
minimum_delegation_amount,
maximum_delegation_amount,
reserved_slots,
);
}
16 changes: 16 additions & 0 deletions smart_contracts/contracts/client/add-reservations/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "add-reservations"
version = "0.1.0"
authors = ["Jacek Chmielewski <[email protected]>"]
edition = "2021"

[[bin]]
name = "add_reservations"
path = "src/main.rs"
bench = false
doctest = false
test = false

[dependencies]
casper-contract = { path = "../../../contract" }
casper-types = { path = "../../../../types" }
24 changes: 24 additions & 0 deletions smart_contracts/contracts/client/add-reservations/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#![no_std]
#![no_main]

extern crate alloc;

use alloc::vec::Vec;

use casper_contract::contract_api::runtime;
use casper_types::system::auction::{Reservation, ARG_RESERVATIONS};

fn add_reservations(_reservations: Vec<Reservation>) {
todo!();
}

// Add delegators to validator's reserved list.
//
// Accepts reservations.
// Issues an add_reservations request to the auction contract.
#[no_mangle]
pub extern "C" fn call() {
let reservations: Vec<Reservation> = runtime::get_named_arg(ARG_RESERVATIONS);

add_reservations(reservations);
}
16 changes: 16 additions & 0 deletions smart_contracts/contracts/client/cancel-reservations/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "cancel-reservations"
version = "0.1.0"
authors = ["Jacek Chmielewski <[email protected]>"]
edition = "2021"

[[bin]]
name = "cancel_reservations"
path = "src/main.rs"
bench = false
doctest = false
test = false

[dependencies]
casper-contract = { path = "../../../contract" }
casper-types = { path = "../../../../types" }
28 changes: 28 additions & 0 deletions smart_contracts/contracts/client/cancel-reservations/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#![no_std]
#![no_main]

extern crate alloc;

use alloc::vec::Vec;

use casper_contract::contract_api::runtime;
use casper_types::{
system::auction::{ARG_DELEGATORS, ARG_VALIDATOR},
PublicKey,
};

fn cancel_reservations(_validator: PublicKey, _delegators: Vec<PublicKey>) {
todo!();
}

// Remove delegators from validator's reserved list.
//
// Accepts delegators' and validator's public keys.
// Issues a cancel_reservations request to the auction contract.
#[no_mangle]
pub extern "C" fn call() {
let delegators: Vec<PublicKey> = runtime::get_named_arg(ARG_DELEGATORS);
let validator = runtime::get_named_arg(ARG_VALIDATOR);

cancel_reservations(validator, delegators);
}
3 changes: 3 additions & 0 deletions storage/src/data_access_layer/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ impl AuctionMethod {
TransactionEntryPoint::ChangeBidPublicKey => {
Self::new_change_bid_public_key(runtime_args)
}
TransactionEntryPoint::AddReservations | TransactionEntryPoint::CancelReservations => {
todo!()
}
}
}

Expand Down
1 change: 1 addition & 0 deletions storage/src/global_state/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,7 @@ pub trait StateProvider {
amount,
minimum_delegation_amount,
maximum_delegation_amount,
0,
)
.map(AuctionMethodRet::UpdatedAmount)
.map_err(TrackingCopyError::Api),
Expand Down
2 changes: 2 additions & 0 deletions storage/src/system/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ pub trait Auction:
amount: U512,
minimum_delegation_amount: u64,
maximum_delegation_amount: u64,
// TODO: reservation list functionality implementation
_reserved_slots: u32,
) -> Result<U512, ApiError> {
if !self.allow_auction_bids() {
// The validator set may be closed on some side chains,
Expand Down
Loading

0 comments on commit 6416c72

Please sign in to comment.