From 3e1db7cd0b1bfcf1041d5c6db559d06f7d7513b7 Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Mon, 1 Jul 2024 09:57:46 +0200 Subject: [PATCH 01/38] Add whitelist_size field to ValidatorBid struct --- types/src/system/auction/validator_bid.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/types/src/system/auction/validator_bid.rs b/types/src/system/auction/validator_bid.rs index 9a835bfe14..6cc50acc51 100644 --- a/types/src/system/auction/validator_bid.rs +++ b/types/src/system/auction/validator_bid.rs @@ -39,6 +39,8 @@ pub struct ValidatorBid { minimum_delegation_amount: u64, /// Maximum allowed delegation amount in motes maximum_delegation_amount: u64, + /// Spots reserved for specific delegators + whitelist_size: u32, } impl ValidatorBid { @@ -63,6 +65,7 @@ impl ValidatorBid { inactive, minimum_delegation_amount, maximum_delegation_amount, + whitelist_size: 0, } } @@ -86,6 +89,7 @@ impl ValidatorBid { inactive, minimum_delegation_amount, maximum_delegation_amount, + whitelist_size: 0, } } @@ -104,6 +108,7 @@ impl ValidatorBid { inactive, minimum_delegation_amount: 0, maximum_delegation_amount: u64::MAX, + whitelist_size: 0, } } @@ -330,6 +335,7 @@ impl FromBytes for ValidatorBid { inactive, minimum_delegation_amount, maximum_delegation_amount, + whitelist_size: 0, }, bytes, )) @@ -347,6 +353,7 @@ impl From for ValidatorBid { inactive: bid.inactive(), minimum_delegation_amount: 0, maximum_delegation_amount: u64::MAX, + whitelist_size: 0, } } } @@ -372,6 +379,7 @@ mod tests { inactive: false, minimum_delegation_amount: 0, maximum_delegation_amount: u64::MAX, + whitelist_size: 0, }; bytesrepr::test_serialization_roundtrip(&founding_validator); } @@ -389,6 +397,7 @@ mod tests { inactive: true, minimum_delegation_amount: 0, maximum_delegation_amount: u64::MAX, + whitelist_size: 0, }; bytesrepr::test_serialization_roundtrip(&founding_validator); } From 3a97eae47a91087fcf73476aa241ae98bd09436c Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Mon, 1 Jul 2024 11:20:36 +0200 Subject: [PATCH 02/38] Add whitelist_size to data schema --- resources/test/sse_data_schema.json | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/resources/test/sse_data_schema.json b/resources/test/sse_data_schema.json index e9b3a5d117..204af3cfad 100644 --- a/resources/test/sse_data_schema.json +++ b/resources/test/sse_data_schema.json @@ -3289,7 +3289,8 @@ "maximum_delegation_amount", "minimum_delegation_amount", "staked_amount", - "validator_public_key" + "validator_public_key", + "whitelist_size" ], "properties": { "validator_public_key": { @@ -3348,6 +3349,12 @@ "type": "integer", "format": "uint64", "minimum": 0.0 + }, + "whitelist_size": { + "description": "Spots reserved for specific delegators", + "type": "integer", + "format": "uint32", + "minimum": 0.0 } }, "additionalProperties": false From 2ddb7a8d9e3904847f1c8be20f43c8ebcc6f3dc1 Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Mon, 1 Jul 2024 13:30:10 +0200 Subject: [PATCH 03/38] Serialize ValidatorBid::whitelist_size --- types/src/system/auction/validator_bid.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/types/src/system/auction/validator_bid.rs b/types/src/system/auction/validator_bid.rs index 6cc50acc51..61338ec669 100644 --- a/types/src/system/auction/validator_bid.rs +++ b/types/src/system/auction/validator_bid.rs @@ -288,6 +288,7 @@ impl ToBytes for ValidatorBid { self.inactive.write_bytes(&mut result)?; self.minimum_delegation_amount.write_bytes(&mut result)?; self.maximum_delegation_amount.write_bytes(&mut result)?; + self.whitelist_size.write_bytes(&mut result)?; Ok(result) } @@ -300,6 +301,7 @@ impl ToBytes for ValidatorBid { + self.inactive.serialized_length() + self.minimum_delegation_amount.serialized_length() + self.maximum_delegation_amount.serialized_length() + + self.whitelist_size.serialized_length() } fn write_bytes(&self, writer: &mut Vec) -> Result<(), bytesrepr::Error> { @@ -311,6 +313,7 @@ impl ToBytes for ValidatorBid { self.inactive.write_bytes(writer)?; self.minimum_delegation_amount.write_bytes(writer)?; self.maximum_delegation_amount.write_bytes(writer)?; + self.whitelist_size.write_bytes(writer)?; Ok(()) } } @@ -325,6 +328,7 @@ impl FromBytes for ValidatorBid { let (inactive, bytes) = FromBytes::from_bytes(bytes)?; let (minimum_delegation_amount, bytes) = FromBytes::from_bytes(bytes)?; let (maximum_delegation_amount, bytes) = FromBytes::from_bytes(bytes)?; + let (whitelist_size, bytes) = FromBytes::from_bytes(bytes)?; Ok(( ValidatorBid { validator_public_key, @@ -335,7 +339,7 @@ impl FromBytes for ValidatorBid { inactive, minimum_delegation_amount, maximum_delegation_amount, - whitelist_size: 0, + whitelist_size, }, bytes, )) From b313d5af89c199a648c0244842899ad0cc764e17 Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Tue, 9 Jul 2024 10:10:17 +0200 Subject: [PATCH 04/38] Rename whitelist_size -> reserved_spots --- resources/test/sse_data_schema.json | 4 ++-- types/src/system/auction/validator_bid.rs | 24 +++++++++++------------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/resources/test/sse_data_schema.json b/resources/test/sse_data_schema.json index 204af3cfad..359c467cf3 100644 --- a/resources/test/sse_data_schema.json +++ b/resources/test/sse_data_schema.json @@ -3290,7 +3290,7 @@ "minimum_delegation_amount", "staked_amount", "validator_public_key", - "whitelist_size" + "reserved_spots" ], "properties": { "validator_public_key": { @@ -3350,7 +3350,7 @@ "format": "uint64", "minimum": 0.0 }, - "whitelist_size": { + "reserved_spots": { "description": "Spots reserved for specific delegators", "type": "integer", "format": "uint32", diff --git a/types/src/system/auction/validator_bid.rs b/types/src/system/auction/validator_bid.rs index 61338ec669..fe35f60ed7 100644 --- a/types/src/system/auction/validator_bid.rs +++ b/types/src/system/auction/validator_bid.rs @@ -40,7 +40,7 @@ pub struct ValidatorBid { /// Maximum allowed delegation amount in motes maximum_delegation_amount: u64, /// Spots reserved for specific delegators - whitelist_size: u32, + reserved_spots: u32, } impl ValidatorBid { @@ -65,7 +65,7 @@ impl ValidatorBid { inactive, minimum_delegation_amount, maximum_delegation_amount, - whitelist_size: 0, + reserved_spots: 0, } } @@ -89,7 +89,7 @@ impl ValidatorBid { inactive, minimum_delegation_amount, maximum_delegation_amount, - whitelist_size: 0, + reserved_spots: 0, } } @@ -108,7 +108,7 @@ impl ValidatorBid { inactive, minimum_delegation_amount: 0, maximum_delegation_amount: u64::MAX, - whitelist_size: 0, + reserved_spots: 0, } } @@ -288,7 +288,7 @@ impl ToBytes for ValidatorBid { self.inactive.write_bytes(&mut result)?; self.minimum_delegation_amount.write_bytes(&mut result)?; self.maximum_delegation_amount.write_bytes(&mut result)?; - self.whitelist_size.write_bytes(&mut result)?; + self.reserved_spots.write_bytes(&mut result)?; Ok(result) } @@ -301,7 +301,7 @@ impl ToBytes for ValidatorBid { + self.inactive.serialized_length() + self.minimum_delegation_amount.serialized_length() + self.maximum_delegation_amount.serialized_length() - + self.whitelist_size.serialized_length() + + self.reserved_spots.serialized_length() } fn write_bytes(&self, writer: &mut Vec) -> Result<(), bytesrepr::Error> { @@ -313,7 +313,7 @@ impl ToBytes for ValidatorBid { self.inactive.write_bytes(writer)?; self.minimum_delegation_amount.write_bytes(writer)?; self.maximum_delegation_amount.write_bytes(writer)?; - self.whitelist_size.write_bytes(writer)?; + self.reserved_spots.write_bytes(writer)?; Ok(()) } } @@ -328,7 +328,7 @@ impl FromBytes for ValidatorBid { let (inactive, bytes) = FromBytes::from_bytes(bytes)?; let (minimum_delegation_amount, bytes) = FromBytes::from_bytes(bytes)?; let (maximum_delegation_amount, bytes) = FromBytes::from_bytes(bytes)?; - let (whitelist_size, bytes) = FromBytes::from_bytes(bytes)?; + let (reserved_spots, bytes) = FromBytes::from_bytes(bytes)?; Ok(( ValidatorBid { validator_public_key, @@ -339,7 +339,7 @@ impl FromBytes for ValidatorBid { inactive, minimum_delegation_amount, maximum_delegation_amount, - whitelist_size, + reserved_spots, }, bytes, )) @@ -357,7 +357,7 @@ impl From for ValidatorBid { inactive: bid.inactive(), minimum_delegation_amount: 0, maximum_delegation_amount: u64::MAX, - whitelist_size: 0, + reserved_spots: 0, } } } @@ -383,7 +383,7 @@ mod tests { inactive: false, minimum_delegation_amount: 0, maximum_delegation_amount: u64::MAX, - whitelist_size: 0, + reserved_spots: 0, }; bytesrepr::test_serialization_roundtrip(&founding_validator); } @@ -401,7 +401,7 @@ mod tests { inactive: true, minimum_delegation_amount: 0, maximum_delegation_amount: u64::MAX, - whitelist_size: 0, + reserved_spots: 0, }; bytesrepr::test_serialization_roundtrip(&founding_validator); } From d4c9ab1b9037c7ebcbb232eb230bc4b1af968075 Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Wed, 10 Jul 2024 09:31:47 +0200 Subject: [PATCH 05/38] Add BidAddr::Reservation, BidAddrTag::Reservation variants --- types/src/system/auction/bid_addr.rs | 47 +++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/types/src/system/auction/bid_addr.rs b/types/src/system/auction/bid_addr.rs index bf14dff653..b043cfffb9 100644 --- a/types/src/system/auction/bid_addr.rs +++ b/types/src/system/auction/bid_addr.rs @@ -23,6 +23,7 @@ const VALIDATOR_TAG: u8 = 1; const DELEGATOR_TAG: u8 = 2; const CREDIT_TAG: u8 = 4; +const RESERVATION_TAG: u8 = 5; /// Serialization tag for BidAddr variants. #[derive( @@ -42,6 +43,9 @@ pub enum BidAddrTag { /// BidAddr for auction credit. Credit = CREDIT_TAG, + + /// BidAddr for reservation bid. + Reservation = RESERVATION_TAG, } impl Display for BidAddrTag { @@ -52,6 +56,7 @@ impl Display for BidAddrTag { BidAddrTag::Delegator => DELEGATOR_TAG, BidAddrTag::Credit => CREDIT_TAG, + BidAddrTag::Reservation => RESERVATION_TAG, }; write!(f, "{}", base16::encode_lower(&[tag])) } @@ -77,6 +82,9 @@ impl BidAddrTag { if value == CREDIT_TAG { return Some(BidAddrTag::Credit); } + if value == RESERVATION_TAG { + return Some(BidAddrTag::Reservation); + } None } @@ -106,6 +114,13 @@ pub enum BidAddr { /// The era id. era_id: EraId, }, + /// Reservation BidAddr + Reservation { + /// The validator addr. + validator: AccountHash, + /// The delegator addr. + delegator: AccountHash, + }, } impl BidAddr { @@ -175,7 +190,9 @@ impl BidAddr { pub fn validator_account_hash(&self) -> AccountHash { match self { BidAddr::Unified(account_hash) | BidAddr::Validator(account_hash) => *account_hash, - BidAddr::Delegator { validator, .. } | BidAddr::Credit { validator, .. } => *validator, + BidAddr::Delegator { validator, .. } + | BidAddr::Credit { validator, .. } + | BidAddr::Reservation { validator, .. } => *validator, } } @@ -183,14 +200,19 @@ impl BidAddr { pub fn maybe_delegator_account_hash(&self) -> Option { match self { BidAddr::Unified(_) | BidAddr::Validator(_) | BidAddr::Credit { .. } => None, - BidAddr::Delegator { delegator, .. } => Some(*delegator), + BidAddr::Delegator { delegator, .. } | BidAddr::Reservation { delegator, .. } => { + Some(*delegator) + } } } /// Era id or none. pub fn maybe_era_id(&self) -> Option { match self { - BidAddr::Unified(_) | BidAddr::Validator(_) | BidAddr::Delegator { .. } => None, + BidAddr::Unified(_) + | BidAddr::Validator(_) + | BidAddr::Delegator { .. } + | BidAddr::Reservation { .. } => None, BidAddr::Credit { era_id, .. } => Some(*era_id), } } @@ -199,7 +221,7 @@ impl BidAddr { /// Else, it is the key for a validator bid record. pub fn is_delegator_bid_addr(&self) -> bool { match self { - BidAddr::Unified(_) | BidAddr::Validator(_) | BidAddr::Credit { .. } => false, + BidAddr::Unified(_) | BidAddr::Validator(_) | BidAddr::Credit { .. } | BidAddr::Reservation { .. } => false, BidAddr::Delegator { .. } => true, } } @@ -217,6 +239,10 @@ impl BidAddr { BidAddr::Credit { validator, era_id } => { ToBytes::serialized_length(validator) + ToBytes::serialized_length(era_id) + 1 } + BidAddr::Reservation { + validator, + delegator, + } => ToBytes::serialized_length(validator) + ToBytes::serialized_length(delegator) + 1, } } @@ -228,6 +254,7 @@ impl BidAddr { BidAddr::Delegator { .. } => BidAddrTag::Delegator, BidAddr::Credit { .. } => BidAddrTag::Credit, + BidAddr::Reservation { .. } => BidAddrTag::Reservation, } } } @@ -324,6 +351,10 @@ impl Display for BidAddr { validator, base16::encode_lower(&era_id.to_le_bytes()) ), + BidAddr::Reservation { + validator, + delegator, + } => write!(f, "{}{}{}", tag, validator, delegator), } } } @@ -340,7 +371,13 @@ impl Debug for BidAddr { write!(f, "BidAddr::Delegator({:?}{:?})", validator, delegator) } BidAddr::Credit { validator, era_id } => { - write!(f, "BidAddr::Delegator({:?}{:?})", validator, era_id) + write!(f, "BidAddr::Credit({:?}{:?})", validator, era_id) + } + BidAddr::Reservation { + validator, + delegator, + } => { + write!(f, "BidAddr::Reservation({:?}{:?})", validator, delegator) } } } From 966f3cf57fb248e2dd06d6b6d463fabb9fd5de25 Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Wed, 10 Jul 2024 11:10:16 +0200 Subject: [PATCH 06/38] Add reserved_spots arg to Auction::add_bid --- execution_engine/src/runtime/mod.rs | 1 + storage/src/global_state/state/mod.rs | 1 + storage/src/system/auction.rs | 1 + 3 files changed, 3 insertions(+) diff --git a/execution_engine/src/runtime/mod.rs b/execution_engine/src/runtime/mod.rs index 9225b25798..04fc908ab6 100644 --- a/execution_engine/src/runtime/mod.rs +++ b/execution_engine/src/runtime/mod.rs @@ -877,6 +877,7 @@ where amount, minimum_delegation_amount, maximum_delegation_amount, + 0, ) .map_err(Self::reverter)?; diff --git a/storage/src/global_state/state/mod.rs b/storage/src/global_state/state/mod.rs index d427caf2ae..e0f779f69c 100644 --- a/storage/src/global_state/state/mod.rs +++ b/storage/src/global_state/state/mod.rs @@ -1212,6 +1212,7 @@ pub trait StateProvider { amount, minimum_delegation_amount, maximum_delegation_amount, + 0, ) .map(AuctionMethodRet::UpdatedAmount) .map_err(TrackingCopyError::Api), diff --git a/storage/src/system/auction.rs b/storage/src/system/auction.rs index e8244fa9fd..17e1ebe0af 100644 --- a/storage/src/system/auction.rs +++ b/storage/src/system/auction.rs @@ -73,6 +73,7 @@ pub trait Auction: amount: U512, minimum_delegation_amount: u64, maximum_delegation_amount: u64, + _reserved_spots: u32, ) -> Result { if !self.allow_auction_bids() { // The validator set may be closed on some side chains, From 22394af474c11619e0c2d8fd04a190e1075e7402 Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Wed, 10 Jul 2024 12:09:40 +0200 Subject: [PATCH 07/38] Add reserved_spots argument to add-bid contract --- smart_contracts/contracts/client/add-bid/src/main.rs | 4 ++++ storage/src/system/auction.rs | 1 + types/src/system/auction/constants.rs | 2 ++ 3 files changed, 7 insertions(+) diff --git a/smart_contracts/contracts/client/add-bid/src/main.rs b/smart_contracts/contracts/client/add-bid/src/main.rs index 0347cf77a8..3941d015a5 100644 --- a/smart_contracts/contracts/client/add-bid/src/main.rs +++ b/smart_contracts/contracts/client/add-bid/src/main.rs @@ -12,12 +12,14 @@ fn add_bid( delegation_rate: auction::DelegationRate, minimum_delegation_amount: Option, maximum_delegation_amount: Option, + reserved_spots: u32, ) { let contract_hash = system::get_auction(); let mut args = runtime_args! { auction::ARG_PUBLIC_KEY => public_key, auction::ARG_AMOUNT => bond_amount, auction::ARG_DELEGATION_RATE => delegation_rate, + auction::ARG_RESERVED_SPOTS => reserved_spots, }; // Optional arguments if let Some(minimum_delegation_amount) = minimum_delegation_amount { @@ -49,6 +51,7 @@ pub extern "C" fn call() { runtime::try_get_named_arg(auction::ARG_MINIMUM_DELEGATION_AMOUNT); let maximum_delegation_amount = runtime::try_get_named_arg(auction::ARG_MAXIMUM_DELEGATION_AMOUNT); + let reserved_spots = runtime::try_get_named_arg(auction::ARG_RESERVED_SPOTS); add_bid( public_key, @@ -56,5 +59,6 @@ pub extern "C" fn call() { delegation_rate, minimum_delegation_amount, maximum_delegation_amount, + reserved_spots, ); } diff --git a/storage/src/system/auction.rs b/storage/src/system/auction.rs index 17e1ebe0af..671441f1a8 100644 --- a/storage/src/system/auction.rs +++ b/storage/src/system/auction.rs @@ -73,6 +73,7 @@ pub trait Auction: amount: U512, minimum_delegation_amount: u64, maximum_delegation_amount: u64, + // TODO: reservation list functionality implementation _reserved_spots: u32, ) -> Result { if !self.allow_auction_bids() { diff --git a/types/src/system/auction/constants.rs b/types/src/system/auction/constants.rs index 8e919436d9..304e384b27 100644 --- a/types/src/system/auction/constants.rs +++ b/types/src/system/auction/constants.rs @@ -62,6 +62,8 @@ pub const ARG_ENTRY_POINT: &str = "entry_point"; pub const ARG_MINIMUM_DELEGATION_AMOUNT: &str = "minimum_delegation_amount"; /// Named constrant for `maximum_delegation_amount`. pub const ARG_MAXIMUM_DELEGATION_AMOUNT: &str = "maximum_delegation_amount"; +/// Named constant for `reserved_spots`. +pub const ARG_RESERVED_SPOTS: &str = "reserved_spots"; /// Named constant for method `get_era_validators`. pub const METHOD_GET_ERA_VALIDATORS: &str = "get_era_validators"; From 48476600150d599239b7a40beabacf178b7e7536 Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Wed, 10 Jul 2024 12:17:49 +0200 Subject: [PATCH 08/38] reserved_spots in runtime::call_host_auction --- execution_engine/src/runtime/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/execution_engine/src/runtime/mod.rs b/execution_engine/src/runtime/mod.rs index 04fc908ab6..73e026e3c8 100644 --- a/execution_engine/src/runtime/mod.rs +++ b/execution_engine/src/runtime/mod.rs @@ -869,6 +869,8 @@ where { return Err(ExecError::Revert(ApiError::InvalidDelegationAmountLimits)); } + let reserved_spots = + Self::get_named_argument(runtime_args, auction::ARG_RESERVED_SPOTS)?; let result = runtime .add_bid( @@ -877,7 +879,7 @@ where amount, minimum_delegation_amount, maximum_delegation_amount, - 0, + reserved_spots, ) .map_err(Self::reverter)?; From 4937ffe7bd5320f0004432795d28fc519d1c05ec Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Wed, 10 Jul 2024 12:29:47 +0200 Subject: [PATCH 09/38] Optional reserved_spots arg --- execution_engine/src/runtime/mod.rs | 7 +++++-- smart_contracts/contracts/client/add-bid/src/main.rs | 10 ++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/execution_engine/src/runtime/mod.rs b/execution_engine/src/runtime/mod.rs index 73e026e3c8..51754faaee 100644 --- a/execution_engine/src/runtime/mod.rs +++ b/execution_engine/src/runtime/mod.rs @@ -869,8 +869,11 @@ where { return Err(ExecError::Revert(ApiError::InvalidDelegationAmountLimits)); } - let reserved_spots = - Self::get_named_argument(runtime_args, auction::ARG_RESERVED_SPOTS)?; + let reserved_spots = Self::try_get_named_argument( + runtime_args, + auction::ARG_RESERVED_SPOTS, + )? + .unwrap_or(0); let result = runtime .add_bid( diff --git a/smart_contracts/contracts/client/add-bid/src/main.rs b/smart_contracts/contracts/client/add-bid/src/main.rs index 3941d015a5..51f876f927 100644 --- a/smart_contracts/contracts/client/add-bid/src/main.rs +++ b/smart_contracts/contracts/client/add-bid/src/main.rs @@ -12,14 +12,13 @@ fn add_bid( delegation_rate: auction::DelegationRate, minimum_delegation_amount: Option, maximum_delegation_amount: Option, - reserved_spots: u32, + reserved_spots: Option, ) { let contract_hash = system::get_auction(); let mut args = runtime_args! { auction::ARG_PUBLIC_KEY => public_key, auction::ARG_AMOUNT => bond_amount, auction::ARG_DELEGATION_RATE => delegation_rate, - auction::ARG_RESERVED_SPOTS => reserved_spots, }; // Optional arguments if let Some(minimum_delegation_amount) = minimum_delegation_amount { @@ -34,6 +33,12 @@ fn add_bid( maximum_delegation_amount, ); } + if let Some(reserved_spots) = reserved_spots { + let _ = args.insert( + auction::ARG_RESERVED_SPOTS, + reserved_spots, + ); + } runtime::call_contract::(contract_hash, auction::METHOD_ADD_BID, args); } @@ -46,6 +51,7 @@ 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 = runtime::try_get_named_arg(auction::ARG_MINIMUM_DELEGATION_AMOUNT); From 0e4ced09e85320150afa73216a7d4ae31afaa497 Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Wed, 10 Jul 2024 16:53:57 +0200 Subject: [PATCH 10/38] Add TransactionEntryPoint::{AddReservation, CancelReservation} variants --- storage/src/data_access_layer/auction.rs | 3 ++ .../test_block_v2_builder.rs | 3 ++ .../transaction/transaction_entry_point.rs | 40 ++++++++++++++++++- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/storage/src/data_access_layer/auction.rs b/storage/src/data_access_layer/auction.rs index 4ea3929672..9f2fa2319e 100644 --- a/storage/src/data_access_layer/auction.rs +++ b/storage/src/data_access_layer/auction.rs @@ -99,6 +99,9 @@ impl AuctionMethod { TransactionEntryPoint::ChangeBidPublicKey => { Self::new_change_bid_public_key(runtime_args) } + TransactionEntryPoint::AddReservation | TransactionEntryPoint::CancelReservation => { + todo!() + } } } diff --git a/types/src/block/test_block_builder/test_block_v2_builder.rs b/types/src/block/test_block_builder/test_block_v2_builder.rs index b693ecd4e7..32efd1005f 100644 --- a/types/src/block/test_block_builder/test_block_v2_builder.rs +++ b/types/src/block/test_block_builder/test_block_v2_builder.rs @@ -202,6 +202,9 @@ impl TestBlockV2Builder { | TransactionEntryPoint::ActivateBid | TransactionEntryPoint::ChangeBidPublicKey => { auction_hashes.push(txn_hash) + }, + TransactionEntryPoint::AddReservation | TransactionEntryPoint::CancelReservation => { + todo!() } }, TransactionTarget::Stored { .. } => standard_hashes.push(txn_hash), diff --git a/types/src/transaction/transaction_entry_point.rs b/types/src/transaction/transaction_entry_point.rs index 46aa200771..9f465c8a4f 100644 --- a/types/src/transaction/transaction_entry_point.rs +++ b/types/src/transaction/transaction_entry_point.rs @@ -29,6 +29,8 @@ const REDELEGATE_TAG: u8 = 6; const ACTIVATE_BID_TAG: u8 = 7; const CHANGE_BID_PUBLIC_KEY_TAG: u8 = 8; const CALL_TAG: u8 = 9; +const ADD_RESERVATION_TAG: u8 = 10; +const CANCEL_RESERVATION_TAG: u8 = 11; /// The entry point of a [`Transaction`]. #[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Serialize, Deserialize, Debug)] @@ -165,6 +167,34 @@ pub enum TransactionEntryPoint { ) )] ChangeBidPublicKey, + /// The `add_reservation` native entry point, used to add delegator to validator's reserve + /// list. + /// + /// Requires the following runtime args: + /// * "delegator": `PublicKey` + /// * "validator": `PublicKey` + #[cfg_attr( + feature = "json-schema", + schemars( + description = "The `add_reservation` native entry point, used to add delegator to \ + validator's reserve list" + ) + )] + AddReservation, + /// The `cancel_reservation` native entry point, used to remove delegator from validator's + /// reserve list. + /// + /// Requires the following runtime args: + /// * "delegator": `PublicKey` + /// * "validator": `PublicKey` + #[cfg_attr( + feature = "json-schema", + schemars( + description = "The `cancel_reservation` native entry point, used to remove delegator \ + from validator's reserve list" + ) + )] + CancelReservation, } impl TransactionEntryPoint { @@ -218,6 +248,8 @@ impl Display for TransactionEntryPoint { TransactionEntryPoint::Redelegate => write!(formatter, "redelegate"), TransactionEntryPoint::ActivateBid => write!(formatter, "activate_bid"), TransactionEntryPoint::ChangeBidPublicKey => write!(formatter, "change_bid_public_key"), + TransactionEntryPoint::AddReservation => write!(formatter, "add_reservation"), + TransactionEntryPoint::CancelReservation => write!(formatter, "cancel_reservation"), } } } @@ -239,7 +271,9 @@ impl ToBytes for TransactionEntryPoint { TransactionEntryPoint::ActivateBid => ACTIVATE_BID_TAG.write_bytes(writer), TransactionEntryPoint::ChangeBidPublicKey => { CHANGE_BID_PUBLIC_KEY_TAG.write_bytes(writer) - } + }, + TransactionEntryPoint::AddReservation => ADD_RESERVATION_TAG.write_bytes(writer), + TransactionEntryPoint::CancelReservation=> CANCEL_RESERVATION_TAG.write_bytes(writer), } } @@ -261,7 +295,9 @@ impl ToBytes for TransactionEntryPoint { | TransactionEntryPoint::Undelegate | TransactionEntryPoint::Redelegate | TransactionEntryPoint::ActivateBid - | TransactionEntryPoint::ChangeBidPublicKey => 0, + | TransactionEntryPoint::ChangeBidPublicKey + | TransactionEntryPoint::AddReservation + | TransactionEntryPoint::CancelReservation => 0 } } } From 844492c67144d31197957a8f3ffda14ce20981af Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Wed, 10 Jul 2024 17:17:55 +0200 Subject: [PATCH 11/38] Finish filling in match branches for new TransactionEntryPoint variants --- node/src/components/transaction_acceptor.rs | 4 +++- types/src/transaction/transaction_entry_point.rs | 5 ++++- types/src/transaction/transaction_v1.rs | 6 ++++++ .../transaction_v1/transaction_v1_body.rs | 14 ++++++++++++-- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/node/src/components/transaction_acceptor.rs b/node/src/components/transaction_acceptor.rs index 44641ac41d..e06d9dc7fa 100644 --- a/node/src/components/transaction_acceptor.rs +++ b/node/src/components/transaction_acceptor.rs @@ -584,7 +584,9 @@ impl TransactionAcceptor { | TransactionEntryPoint::Undelegate | TransactionEntryPoint::Redelegate | TransactionEntryPoint::ActivateBid - | TransactionEntryPoint::ChangeBidPublicKey => None, + | TransactionEntryPoint::ChangeBidPublicKey + | TransactionEntryPoint::AddReservation + | TransactionEntryPoint::CancelReservation => None }, }; diff --git a/types/src/transaction/transaction_entry_point.rs b/types/src/transaction/transaction_entry_point.rs index 9f465c8a4f..6ff47a2373 100644 --- a/types/src/transaction/transaction_entry_point.rs +++ b/types/src/transaction/transaction_entry_point.rs @@ -228,7 +228,10 @@ impl TransactionEntryPoint { | TransactionEntryPoint::Undelegate | TransactionEntryPoint::Redelegate | TransactionEntryPoint::ActivateBid - | TransactionEntryPoint::ChangeBidPublicKey => false, + | TransactionEntryPoint::ChangeBidPublicKey + // TODO(jck): make sure this is correct + | TransactionEntryPoint::AddReservation + | TransactionEntryPoint::CancelReservation => false } } } diff --git a/types/src/transaction/transaction_v1.rs b/types/src/transaction/transaction_v1.rs index 3514e92082..aa3a97ec7a 100644 --- a/types/src/transaction/transaction_v1.rs +++ b/types/src/transaction/transaction_v1.rs @@ -650,6 +650,12 @@ impl GasLimited for TransactionV1 { TransactionEntryPoint::ChangeBidPublicKey => { costs.auction_costs().change_bid_public_key } + TransactionEntryPoint::AddReservation => { + todo!() + } + TransactionEntryPoint::CancelReservation => { + todo!() + } }; amount } else { diff --git a/types/src/transaction/transaction_v1/transaction_v1_body.rs b/types/src/transaction/transaction_v1/transaction_v1_body.rs index 473fc1beeb..fd7ab33347 100644 --- a/types/src/transaction/transaction_v1/transaction_v1_body.rs +++ b/types/src/transaction/transaction_v1/transaction_v1_body.rs @@ -207,6 +207,12 @@ impl TransactionV1Body { TransactionEntryPoint::ChangeBidPublicKey => { arg_handling::has_valid_change_bid_public_key_args(&self.args) } + TransactionEntryPoint::AddReservation => { + todo!() + } + TransactionEntryPoint::CancelReservation => { + todo!() + } }, TransactionTarget::Stored { .. } => match &self.entry_point { TransactionEntryPoint::Custom(_) => Ok(()), @@ -218,7 +224,9 @@ impl TransactionV1Body { | TransactionEntryPoint::Undelegate | TransactionEntryPoint::Redelegate | TransactionEntryPoint::ActivateBid - | TransactionEntryPoint::ChangeBidPublicKey => { + | TransactionEntryPoint::ChangeBidPublicKey + | TransactionEntryPoint::AddReservation + | TransactionEntryPoint::CancelReservation => { debug!( entry_point = %self.entry_point, "transaction targeting stored entity/package must have custom entry point" @@ -243,7 +251,9 @@ impl TransactionV1Body { | TransactionEntryPoint::Undelegate | TransactionEntryPoint::Redelegate | TransactionEntryPoint::ActivateBid - | TransactionEntryPoint::ChangeBidPublicKey => { + | TransactionEntryPoint::ChangeBidPublicKey + | TransactionEntryPoint::AddReservation + | TransactionEntryPoint::CancelReservation => { debug!( entry_point = %self.entry_point, "transaction with session code must use custom or default 'call' entry point" From bb755522d9f2957b5f34c8ec895d2da67b0de7b2 Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Wed, 10 Jul 2024 17:37:49 +0200 Subject: [PATCH 12/38] Add/cancel reservation smart contracts --- Cargo.lock | 16 ++++++++++ .../client/add-reservation/Cargo.toml | 16 ++++++++++ .../client/add-reservation/src/main.rs | 31 +++++++++++++++++++ .../client/cancel-reservation/Cargo.toml | 16 ++++++++++ .../client/cancel-reservation/src/main.rs | 31 +++++++++++++++++++ types/src/system/auction/constants.rs | 4 +++ 6 files changed, 114 insertions(+) create mode 100644 smart_contracts/contracts/client/add-reservation/Cargo.toml create mode 100644 smart_contracts/contracts/client/add-reservation/src/main.rs create mode 100644 smart_contracts/contracts/client/cancel-reservation/Cargo.toml create mode 100644 smart_contracts/contracts/client/cancel-reservation/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index ae53866b72..c9ecda0e66 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -34,6 +34,14 @@ dependencies = [ "casper-types", ] +[[package]] +name = "add-reservation" +version = "0.1.0" +dependencies = [ + "casper-contract", + "casper-types", +] + [[package]] name = "add-update-associated-key" version = "0.1.0" @@ -443,6 +451,14 @@ dependencies = [ "casper-types", ] +[[package]] +name = "cancel-reservation" +version = "0.1.0" +dependencies = [ + "casper-contract", + "casper-types", +] + [[package]] name = "casper-binary-port" version = "1.0.0" diff --git a/smart_contracts/contracts/client/add-reservation/Cargo.toml b/smart_contracts/contracts/client/add-reservation/Cargo.toml new file mode 100644 index 0000000000..72b2f7b383 --- /dev/null +++ b/smart_contracts/contracts/client/add-reservation/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "add-reservation" +version = "0.1.0" +authors = ["Jacek Chmielewski "] +edition = "2021" + +[[bin]] +name = "add_reservation" +path = "src/main.rs" +bench = false +doctest = false +test = false + +[dependencies] +casper-contract = { path = "../../../contract" } +casper-types = { path = "../../../../types" } diff --git a/smart_contracts/contracts/client/add-reservation/src/main.rs b/smart_contracts/contracts/client/add-reservation/src/main.rs new file mode 100644 index 0000000000..8bc391575c --- /dev/null +++ b/smart_contracts/contracts/client/add-reservation/src/main.rs @@ -0,0 +1,31 @@ +#![no_std] +#![no_main] + +extern crate alloc; + +use casper_contract::contract_api::{runtime, system}; +use casper_types::{runtime_args, system::auction, PublicKey, U512}; + +const ARG_VALIDATOR: &str = "validator"; +const ARG_DELEGATOR: &str = "delegator"; + +fn add_reservation(delegator: PublicKey, validator: PublicKey) { + let contract_hash = system::get_auction(); + let args = runtime_args! { + auction::ARG_DELEGATOR => delegator, + auction::ARG_VALIDATOR => validator, + }; + runtime::call_contract::(contract_hash, auction::METHOD_ADD_RESERVATION, args); +} + +// Add delegator to validator's reserved list. +// +// Accepts delegator's and validator's public keys. +// Issues an add_reservation request to the auction contract. +#[no_mangle] +pub extern "C" fn call() { + let delegator = runtime::get_named_arg(ARG_DELEGATOR); + let validator = runtime::get_named_arg(ARG_VALIDATOR); + + add_reservation(delegator, validator); +} diff --git a/smart_contracts/contracts/client/cancel-reservation/Cargo.toml b/smart_contracts/contracts/client/cancel-reservation/Cargo.toml new file mode 100644 index 0000000000..eca418a7a3 --- /dev/null +++ b/smart_contracts/contracts/client/cancel-reservation/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "cancel-reservation" +version = "0.1.0" +authors = ["Jacek Chmielewski "] +edition = "2021" + +[[bin]] +name = "cancel_reservation" +path = "src/main.rs" +bench = false +doctest = false +test = false + +[dependencies] +casper-contract = { path = "../../../contract" } +casper-types = { path = "../../../../types" } diff --git a/smart_contracts/contracts/client/cancel-reservation/src/main.rs b/smart_contracts/contracts/client/cancel-reservation/src/main.rs new file mode 100644 index 0000000000..f5d45da78e --- /dev/null +++ b/smart_contracts/contracts/client/cancel-reservation/src/main.rs @@ -0,0 +1,31 @@ +#![no_std] +#![no_main] + +extern crate alloc; + +use casper_contract::contract_api::{runtime, system}; +use casper_types::{runtime_args, system::auction, PublicKey, U512}; + +const ARG_VALIDATOR: &str = "validator"; +const ARG_DELEGATOR: &str = "delegator"; + +fn cancel_reservation(delegator: PublicKey, validator: PublicKey) { + let contract_hash = system::get_auction(); + let args = runtime_args! { + auction::ARG_DELEGATOR => delegator, + auction::ARG_VALIDATOR => validator, + }; + runtime::call_contract::(contract_hash, auction::METHOD_CANCEL_RESERVATION, args); +} + +// Remove delegator from validator's reserved list. +// +// Accepts delegator's and validator's public keys. +// Issues a cancel_reservation request to the auction contract. +#[no_mangle] +pub extern "C" fn call() { + let delegator = runtime::get_named_arg(ARG_DELEGATOR); + let validator = runtime::get_named_arg(ARG_VALIDATOR); + + cancel_reservation(delegator, validator); +} diff --git a/types/src/system/auction/constants.rs b/types/src/system/auction/constants.rs index 304e384b27..e2267dc203 100644 --- a/types/src/system/auction/constants.rs +++ b/types/src/system/auction/constants.rs @@ -89,6 +89,10 @@ pub const METHOD_READ_ERA_ID: &str = "read_era_id"; pub const METHOD_ACTIVATE_BID: &str = "activate_bid"; /// Named constant for method `change_bid_public_key`. pub const METHOD_CHANGE_BID_PUBLIC_KEY: &str = " change_bid_public_key"; +/// Named constant for method `add_reservation`. +pub const METHOD_ADD_RESERVATION: &str = "add_reservation"; +/// Named constant for method `cancel_reservation`. +pub const METHOD_CANCEL_RESERVATION: &str = "cancel_reservation"; /// Storage for `EraId`. pub const ERA_ID_KEY: &str = "era_id"; From f4ca422025071a1eaf068e9ed3831ec27c0e8c46 Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Wed, 10 Jul 2024 18:22:55 +0200 Subject: [PATCH 13/38] Add reservation variants to Runtime::call_host_action --- execution_engine/src/runtime/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/execution_engine/src/runtime/mod.rs b/execution_engine/src/runtime/mod.rs index 51754faaee..6c2aec5cb1 100644 --- a/execution_engine/src/runtime/mod.rs +++ b/execution_engine/src/runtime/mod.rs @@ -1026,6 +1026,8 @@ where CLValue::from_t(()).map_err(Self::reverter) })(), + auction::METHOD_ADD_RESERVATION => todo!(), + auction::METHOD_CANCEL_RESERVATION => todo!(), _ => CLValue::from_t(()).map_err(Self::reverter), }; From 332da39b017c951594af09effd1c9ad084f54058 Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Wed, 10 Jul 2024 18:41:20 +0200 Subject: [PATCH 14/38] Rename reserved_spots -> reserved_slots --- execution_engine/src/runtime/mod.rs | 6 ++--- resources/test/sse_data_schema.json | 6 ++--- .../contracts/client/add-bid/src/main.rs | 12 ++++----- storage/src/system/auction.rs | 2 +- types/src/system/auction/constants.rs | 4 +-- types/src/system/auction/validator_bid.rs | 26 +++++++++---------- .../transaction/transaction_entry_point.rs | 1 - 7 files changed, 28 insertions(+), 29 deletions(-) diff --git a/execution_engine/src/runtime/mod.rs b/execution_engine/src/runtime/mod.rs index 6c2aec5cb1..0ffacbea7b 100644 --- a/execution_engine/src/runtime/mod.rs +++ b/execution_engine/src/runtime/mod.rs @@ -869,9 +869,9 @@ where { return Err(ExecError::Revert(ApiError::InvalidDelegationAmountLimits)); } - let reserved_spots = Self::try_get_named_argument( + let reserved_slots = Self::try_get_named_argument( runtime_args, - auction::ARG_RESERVED_SPOTS, + auction::ARG_RESERVED_SLOTS, )? .unwrap_or(0); @@ -882,7 +882,7 @@ where amount, minimum_delegation_amount, maximum_delegation_amount, - reserved_spots, + reserved_slots, ) .map_err(Self::reverter)?; diff --git a/resources/test/sse_data_schema.json b/resources/test/sse_data_schema.json index 359c467cf3..4b94915d5e 100644 --- a/resources/test/sse_data_schema.json +++ b/resources/test/sse_data_schema.json @@ -3290,7 +3290,7 @@ "minimum_delegation_amount", "staked_amount", "validator_public_key", - "reserved_spots" + "reserved_slots" ], "properties": { "validator_public_key": { @@ -3350,8 +3350,8 @@ "format": "uint64", "minimum": 0.0 }, - "reserved_spots": { - "description": "Spots reserved for specific delegators", + "reserved_slots": { + "description": "Slots reserved for specific delegators", "type": "integer", "format": "uint32", "minimum": 0.0 diff --git a/smart_contracts/contracts/client/add-bid/src/main.rs b/smart_contracts/contracts/client/add-bid/src/main.rs index 51f876f927..90b213e5f2 100644 --- a/smart_contracts/contracts/client/add-bid/src/main.rs +++ b/smart_contracts/contracts/client/add-bid/src/main.rs @@ -12,7 +12,7 @@ fn add_bid( delegation_rate: auction::DelegationRate, minimum_delegation_amount: Option, maximum_delegation_amount: Option, - reserved_spots: Option, + reserved_slots: Option, ) { let contract_hash = system::get_auction(); let mut args = runtime_args! { @@ -33,10 +33,10 @@ fn add_bid( maximum_delegation_amount, ); } - if let Some(reserved_spots) = reserved_spots { + if let Some(reserved_slots) = reserved_slots { let _ = args.insert( - auction::ARG_RESERVED_SPOTS, - reserved_spots, + auction::ARG_RESERVED_SLOTS, + reserved_slots, ); } runtime::call_contract::(contract_hash, auction::METHOD_ADD_BID, args); @@ -57,7 +57,7 @@ pub extern "C" fn call() { runtime::try_get_named_arg(auction::ARG_MINIMUM_DELEGATION_AMOUNT); let maximum_delegation_amount = runtime::try_get_named_arg(auction::ARG_MAXIMUM_DELEGATION_AMOUNT); - let reserved_spots = runtime::try_get_named_arg(auction::ARG_RESERVED_SPOTS); + let reserved_slots = runtime::try_get_named_arg(auction::ARG_RESERVED_SLOTS); add_bid( public_key, @@ -65,6 +65,6 @@ pub extern "C" fn call() { delegation_rate, minimum_delegation_amount, maximum_delegation_amount, - reserved_spots, + reserved_slots, ); } diff --git a/storage/src/system/auction.rs b/storage/src/system/auction.rs index 671441f1a8..19cd7b7da2 100644 --- a/storage/src/system/auction.rs +++ b/storage/src/system/auction.rs @@ -74,7 +74,7 @@ pub trait Auction: minimum_delegation_amount: u64, maximum_delegation_amount: u64, // TODO: reservation list functionality implementation - _reserved_spots: u32, + _reserved_slots: u32, ) -> Result { if !self.allow_auction_bids() { // The validator set may be closed on some side chains, diff --git a/types/src/system/auction/constants.rs b/types/src/system/auction/constants.rs index e2267dc203..8f96645b25 100644 --- a/types/src/system/auction/constants.rs +++ b/types/src/system/auction/constants.rs @@ -62,8 +62,8 @@ pub const ARG_ENTRY_POINT: &str = "entry_point"; pub const ARG_MINIMUM_DELEGATION_AMOUNT: &str = "minimum_delegation_amount"; /// Named constrant for `maximum_delegation_amount`. pub const ARG_MAXIMUM_DELEGATION_AMOUNT: &str = "maximum_delegation_amount"; -/// Named constant for `reserved_spots`. -pub const ARG_RESERVED_SPOTS: &str = "reserved_spots"; +/// Named constant for `reserved_slots`. +pub const ARG_RESERVED_SLOTS: &str = "reserved_slots"; /// Named constant for method `get_era_validators`. pub const METHOD_GET_ERA_VALIDATORS: &str = "get_era_validators"; diff --git a/types/src/system/auction/validator_bid.rs b/types/src/system/auction/validator_bid.rs index fe35f60ed7..7a01e71e18 100644 --- a/types/src/system/auction/validator_bid.rs +++ b/types/src/system/auction/validator_bid.rs @@ -39,8 +39,8 @@ pub struct ValidatorBid { minimum_delegation_amount: u64, /// Maximum allowed delegation amount in motes maximum_delegation_amount: u64, - /// Spots reserved for specific delegators - reserved_spots: u32, + /// Slots reserved for specific delegators + reserved_slots: u32, } impl ValidatorBid { @@ -65,7 +65,7 @@ impl ValidatorBid { inactive, minimum_delegation_amount, maximum_delegation_amount, - reserved_spots: 0, + reserved_slots: 0, } } @@ -89,7 +89,7 @@ impl ValidatorBid { inactive, minimum_delegation_amount, maximum_delegation_amount, - reserved_spots: 0, + reserved_slots: 0, } } @@ -108,7 +108,7 @@ impl ValidatorBid { inactive, minimum_delegation_amount: 0, maximum_delegation_amount: u64::MAX, - reserved_spots: 0, + reserved_slots: 0, } } @@ -288,7 +288,7 @@ impl ToBytes for ValidatorBid { self.inactive.write_bytes(&mut result)?; self.minimum_delegation_amount.write_bytes(&mut result)?; self.maximum_delegation_amount.write_bytes(&mut result)?; - self.reserved_spots.write_bytes(&mut result)?; + self.reserved_slots.write_bytes(&mut result)?; Ok(result) } @@ -301,7 +301,7 @@ impl ToBytes for ValidatorBid { + self.inactive.serialized_length() + self.minimum_delegation_amount.serialized_length() + self.maximum_delegation_amount.serialized_length() - + self.reserved_spots.serialized_length() + + self.reserved_slots.serialized_length() } fn write_bytes(&self, writer: &mut Vec) -> Result<(), bytesrepr::Error> { @@ -313,7 +313,7 @@ impl ToBytes for ValidatorBid { self.inactive.write_bytes(writer)?; self.minimum_delegation_amount.write_bytes(writer)?; self.maximum_delegation_amount.write_bytes(writer)?; - self.reserved_spots.write_bytes(writer)?; + self.reserved_slots.write_bytes(writer)?; Ok(()) } } @@ -328,7 +328,7 @@ impl FromBytes for ValidatorBid { let (inactive, bytes) = FromBytes::from_bytes(bytes)?; let (minimum_delegation_amount, bytes) = FromBytes::from_bytes(bytes)?; let (maximum_delegation_amount, bytes) = FromBytes::from_bytes(bytes)?; - let (reserved_spots, bytes) = FromBytes::from_bytes(bytes)?; + let (reserved_slots, bytes) = FromBytes::from_bytes(bytes)?; Ok(( ValidatorBid { validator_public_key, @@ -339,7 +339,7 @@ impl FromBytes for ValidatorBid { inactive, minimum_delegation_amount, maximum_delegation_amount, - reserved_spots, + reserved_slots, }, bytes, )) @@ -357,7 +357,7 @@ impl From for ValidatorBid { inactive: bid.inactive(), minimum_delegation_amount: 0, maximum_delegation_amount: u64::MAX, - reserved_spots: 0, + reserved_slots: 0, } } } @@ -383,7 +383,7 @@ mod tests { inactive: false, minimum_delegation_amount: 0, maximum_delegation_amount: u64::MAX, - reserved_spots: 0, + reserved_slots: 0, }; bytesrepr::test_serialization_roundtrip(&founding_validator); } @@ -401,7 +401,7 @@ mod tests { inactive: true, minimum_delegation_amount: 0, maximum_delegation_amount: u64::MAX, - reserved_spots: 0, + reserved_slots: 0, }; bytesrepr::test_serialization_roundtrip(&founding_validator); } diff --git a/types/src/transaction/transaction_entry_point.rs b/types/src/transaction/transaction_entry_point.rs index 6ff47a2373..38ec8752f8 100644 --- a/types/src/transaction/transaction_entry_point.rs +++ b/types/src/transaction/transaction_entry_point.rs @@ -229,7 +229,6 @@ impl TransactionEntryPoint { | TransactionEntryPoint::Redelegate | TransactionEntryPoint::ActivateBid | TransactionEntryPoint::ChangeBidPublicKey - // TODO(jck): make sure this is correct | TransactionEntryPoint::AddReservation | TransactionEntryPoint::CancelReservation => false } From 75a393dead235dfa3ba42f00fc70abac1eda6c37 Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Thu, 11 Jul 2024 09:07:12 +0200 Subject: [PATCH 15/38] Add reservation auction costs --- .../src/chainspec/vm_config/auction_costs.rs | 28 +++++++++++++++++++ types/src/transaction/transaction_v1.rs | 4 +-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/types/src/chainspec/vm_config/auction_costs.rs b/types/src/chainspec/vm_config/auction_costs.rs index 3e85a5a96c..8f6cb7b181 100644 --- a/types/src/chainspec/vm_config/auction_costs.rs +++ b/types/src/chainspec/vm_config/auction_costs.rs @@ -40,6 +40,10 @@ pub const DEFAULT_READ_ERA_ID_COST: u32 = 10_000; pub const DEFAULT_ACTIVATE_BID_COST: u32 = 10_000; /// Default cost of the `change_bid_public_key` auction entry point. pub const DEFAULT_CHANGE_BID_PUBLIC_KEY_COST: u64 = 5_000_000_000; +/// Default cost of the `add_reservation` auction entry point. +pub const DEFAULT_ADD_RESERVATION_COST: u32 = DEFAULT_ADD_BID_COST; +/// Default cost of the `cancel_reservation` auction entry point. +pub const DEFAULT_CANCEL_RESERVATION_COST: u32 = DEFAULT_ADD_BID_COST; /// Description of the costs of calling auction entrypoints. #[derive(Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Debug)] @@ -76,6 +80,10 @@ pub struct AuctionCosts { pub redelegate: u32, /// Cost of calling the `change_bid_public_key` entry point. pub change_bid_public_key: u64, + /// Cost of calling the `add_reservation` entry point. + pub add_reservation: u32, + /// Cost of calling the `cancel_reservation` entry point. + pub cancel_reservation: u32, } impl Default for AuctionCosts { @@ -96,6 +104,8 @@ impl Default for AuctionCosts { activate_bid: DEFAULT_ACTIVATE_BID_COST, redelegate: DEFAULT_REDELEGATE_COST, change_bid_public_key: DEFAULT_CHANGE_BID_PUBLIC_KEY_COST, + add_reservation: DEFAULT_ADD_RESERVATION_COST, + cancel_reservation: DEFAULT_CANCEL_RESERVATION_COST, } } } @@ -120,6 +130,8 @@ impl ToBytes for AuctionCosts { activate_bid, redelegate, change_bid_public_key, + add_reservation, + cancel_reservation, } = self; ret.append(&mut get_era_validators.to_bytes()?); @@ -137,6 +149,8 @@ impl ToBytes for AuctionCosts { ret.append(&mut activate_bid.to_bytes()?); ret.append(&mut redelegate.to_bytes()?); ret.append(&mut change_bid_public_key.to_bytes()?); + ret.append(&mut add_reservation.to_bytes()?); + ret.append(&mut cancel_reservation.to_bytes()?); Ok(ret) } @@ -158,6 +172,8 @@ impl ToBytes for AuctionCosts { activate_bid, redelegate, change_bid_public_key, + add_reservation, + cancel_reservation, } = self; get_era_validators.serialized_length() @@ -175,6 +191,8 @@ impl ToBytes for AuctionCosts { + activate_bid.serialized_length() + redelegate.serialized_length() + change_bid_public_key.serialized_length() + + add_reservation.serialized_length() + + cancel_reservation.serialized_length() } } @@ -195,6 +213,8 @@ impl FromBytes for AuctionCosts { let (activate_bid, rem) = FromBytes::from_bytes(rem)?; let (redelegate, rem) = FromBytes::from_bytes(rem)?; let (change_bid_public_key, rem) = FromBytes::from_bytes(rem)?; + let (add_reservation, rem) = FromBytes::from_bytes(rem)?; + let (cancel_reservation, rem) = FromBytes::from_bytes(rem)?; Ok(( Self { get_era_validators, @@ -212,6 +232,8 @@ impl FromBytes for AuctionCosts { activate_bid, redelegate, change_bid_public_key, + add_reservation, + cancel_reservation, }, rem, )) @@ -241,6 +263,8 @@ impl Distribution for Standard { activate_bid: rng.gen(), redelegate: rng.gen(), change_bid_public_key, + add_reservation: rng.gen(), + cancel_reservation: rng.gen(), } } } @@ -269,6 +293,8 @@ pub mod gens { activate_bid in num::u32::ANY, redelegate in num::u32::ANY, change_bid_public_key in num::u64::ANY, + add_reservation in num::u32::ANY, + cancel_reservation in num::u32::ANY, ) -> AuctionCosts { AuctionCosts { get_era_validators, @@ -286,6 +312,8 @@ pub mod gens { activate_bid, redelegate, change_bid_public_key, + add_reservation, + cancel_reservation, } } } diff --git a/types/src/transaction/transaction_v1.rs b/types/src/transaction/transaction_v1.rs index aa3a97ec7a..da9cb21daa 100644 --- a/types/src/transaction/transaction_v1.rs +++ b/types/src/transaction/transaction_v1.rs @@ -651,10 +651,10 @@ impl GasLimited for TransactionV1 { costs.auction_costs().change_bid_public_key } TransactionEntryPoint::AddReservation => { - todo!() + costs.auction_costs().add_reservation.into() } TransactionEntryPoint::CancelReservation => { - todo!() + costs.auction_costs().cancel_reservation.into() } }; amount From dee9336e44518401ef3a6c1756703b234ca4b7e7 Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Thu, 11 Jul 2024 09:55:15 +0200 Subject: [PATCH 16/38] Add reservation costs to config files --- resources/local/chainspec.toml.in | 2 ++ resources/production/chainspec.toml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/resources/local/chainspec.toml.in b/resources/local/chainspec.toml.in index 3f41bdfed6..dedf07bf2d 100644 --- a/resources/local/chainspec.toml.in +++ b/resources/local/chainspec.toml.in @@ -344,6 +344,8 @@ read_era_id = 10_000 activate_bid = 10_000 redelegate = 2_500_000_000 change_bid_public_key = 5_000_000_000 +add_reservation = 2_500_000_000 +cancel_reservation = 2_500_000_000 [system_costs.mint_costs] mint = 2_500_000_000 diff --git a/resources/production/chainspec.toml b/resources/production/chainspec.toml index b351eccc99..38a04e0661 100644 --- a/resources/production/chainspec.toml +++ b/resources/production/chainspec.toml @@ -354,6 +354,8 @@ read_era_id = 10_000 activate_bid = 10_000 redelegate = 2_500_000_000 change_bid_public_key = 5_000_000_000 +add_reservation = 2_500_000_000 +cancel_reservation = 2_500_000_000 [system_costs.mint_costs] mint = 2_500_000_000 From 2de7ccd96b74fcbc1523ace6b34a27693ca01f13 Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Thu, 11 Jul 2024 10:26:21 +0200 Subject: [PATCH 17/38] Update json schema with reservation fields --- resources/test/sse_data_schema.json | 18 ++++++++++++++++-- .../tests/fixtures/ABI/stored_value.json | 7 ++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/resources/test/sse_data_schema.json b/resources/test/sse_data_schema.json index 4b94915d5e..d1c0ae2667 100644 --- a/resources/test/sse_data_schema.json +++ b/resources/test/sse_data_schema.json @@ -2095,6 +2095,20 @@ "enum": [ "ChangeBidPublicKey" ] + }, + { + "description": "The `add_reservation` native entry point, used to add delegator to validator's reserve list", + "type": "string", + "enum": [ + "AddReservation" + ] + }, + { + "description": "The `cancel_reservation` native entry point, used to remove delegator from validator's reserve list", + "type": "string", + "enum": [ + "CancelReservation" + ] } ] }, @@ -3288,9 +3302,9 @@ "inactive", "maximum_delegation_amount", "minimum_delegation_amount", + "reserved_slots", "staked_amount", - "validator_public_key", - "reserved_slots" + "validator_public_key" ], "properties": { "validator_public_key": { diff --git a/utils/validation/tests/fixtures/ABI/stored_value.json b/utils/validation/tests/fixtures/ABI/stored_value.json index 9538e6ad17..e3663fd9cd 100644 --- a/utils/validation/tests/fixtures/ABI/stored_value.json +++ b/utils/validation/tests/fixtures/ABI/stored_value.json @@ -371,14 +371,15 @@ "locked_amounts": null }, "inactive": false, + "minimum_delegation_amount": 0, "maximum_delegation_amount": 18446744073709551615, - "minimum_delegation_amount": 0 + "reserved_slots": 0 } } } } ], - "output": "0b0101197f6b23e16c8532c6abc838facd5ea789be0c76b2920334039bfa8b3d368d610a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a070500743ba40b6401ffffffffffffffff00000000000000000000ffffffffffffffff" + "output": "0b0101197f6b23e16c8532c6abc838facd5ea789be0c76b2920334039bfa8b3d368d610a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a070500743ba40b6401ffffffffffffffff00000000000000000000ffffffffffffffff00000000" }, "Withdraw": { "input": [ @@ -406,4 +407,4 @@ ], "output": "09020000000a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0101197f6b23e16c8532c6abc838facd5ea789be0c76b2920334039bfa8b3d368d6101197f6b23e16c8532c6abc838facd5ea789be0c76b2920334039bfa8b3d368d61290000000000000005005847f80d0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0101197f6b23e16c8532c6abc838facd5ea789be0c76b2920334039bfa8b3d368d610202bb58b5feca505c74edc000d8282fc556e51a1024fc8e7d7e56c6f887c5c8d5f22a000000000000000500743ba40b" } -} +} \ No newline at end of file From afc0978185d1eaee9c7f97147fc0478340028a4e Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Thu, 11 Jul 2024 15:01:20 +0200 Subject: [PATCH 18/38] Fix args retrieval in add-bid contract --- smart_contracts/contracts/client/add-bid/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smart_contracts/contracts/client/add-bid/src/main.rs b/smart_contracts/contracts/client/add-bid/src/main.rs index d61bc46ec6..15c8d53e64 100644 --- a/smart_contracts/contracts/client/add-bid/src/main.rs +++ b/smart_contracts/contracts/client/add-bid/src/main.rs @@ -111,7 +111,7 @@ pub extern "C" fn call() { // 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 = runtime::get_optional_named_args(auction::ARG_RESERVED_SLOTS); + let reserved_slots = get_optional_named_args(auction::ARG_RESERVED_SLOTS); add_bid( public_key, From 827747f4b3fcf408c52cdfd8efaf4dfde075dcb7 Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Thu, 11 Jul 2024 16:22:05 +0200 Subject: [PATCH 19/38] Reservation management methods take arrays of delegators --- Cargo.lock | 4 +-- .../client/add-reservation/src/main.rs | 31 ---------------- .../Cargo.toml | 4 +-- .../client/add-reservations/src/main.rs | 35 +++++++++++++++++++ .../client/cancel-reservation/src/main.rs | 31 ---------------- .../Cargo.toml | 4 +-- .../client/cancel-reservations/src/main.rs | 35 +++++++++++++++++++ 7 files changed, 76 insertions(+), 68 deletions(-) delete mode 100644 smart_contracts/contracts/client/add-reservation/src/main.rs rename smart_contracts/contracts/client/{add-reservation => add-reservations}/Cargo.toml (84%) create mode 100644 smart_contracts/contracts/client/add-reservations/src/main.rs delete mode 100644 smart_contracts/contracts/client/cancel-reservation/src/main.rs rename smart_contracts/contracts/client/{cancel-reservation => cancel-reservations}/Cargo.toml (83%) create mode 100644 smart_contracts/contracts/client/cancel-reservations/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index d26f5c8a6b..eebba647d2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -35,7 +35,7 @@ dependencies = [ ] [[package]] -name = "add-reservation" +name = "add-reservations" version = "0.1.0" dependencies = [ "casper-contract", @@ -452,7 +452,7 @@ dependencies = [ ] [[package]] -name = "cancel-reservation" +name = "cancel-reservations" version = "0.1.0" dependencies = [ "casper-contract", diff --git a/smart_contracts/contracts/client/add-reservation/src/main.rs b/smart_contracts/contracts/client/add-reservation/src/main.rs deleted file mode 100644 index 8bc391575c..0000000000 --- a/smart_contracts/contracts/client/add-reservation/src/main.rs +++ /dev/null @@ -1,31 +0,0 @@ -#![no_std] -#![no_main] - -extern crate alloc; - -use casper_contract::contract_api::{runtime, system}; -use casper_types::{runtime_args, system::auction, PublicKey, U512}; - -const ARG_VALIDATOR: &str = "validator"; -const ARG_DELEGATOR: &str = "delegator"; - -fn add_reservation(delegator: PublicKey, validator: PublicKey) { - let contract_hash = system::get_auction(); - let args = runtime_args! { - auction::ARG_DELEGATOR => delegator, - auction::ARG_VALIDATOR => validator, - }; - runtime::call_contract::(contract_hash, auction::METHOD_ADD_RESERVATION, args); -} - -// Add delegator to validator's reserved list. -// -// Accepts delegator's and validator's public keys. -// Issues an add_reservation request to the auction contract. -#[no_mangle] -pub extern "C" fn call() { - let delegator = runtime::get_named_arg(ARG_DELEGATOR); - let validator = runtime::get_named_arg(ARG_VALIDATOR); - - add_reservation(delegator, validator); -} diff --git a/smart_contracts/contracts/client/add-reservation/Cargo.toml b/smart_contracts/contracts/client/add-reservations/Cargo.toml similarity index 84% rename from smart_contracts/contracts/client/add-reservation/Cargo.toml rename to smart_contracts/contracts/client/add-reservations/Cargo.toml index 72b2f7b383..1381a63864 100644 --- a/smart_contracts/contracts/client/add-reservation/Cargo.toml +++ b/smart_contracts/contracts/client/add-reservations/Cargo.toml @@ -1,11 +1,11 @@ [package] -name = "add-reservation" +name = "add-reservations" version = "0.1.0" authors = ["Jacek Chmielewski "] edition = "2021" [[bin]] -name = "add_reservation" +name = "add_reservations" path = "src/main.rs" bench = false doctest = false diff --git a/smart_contracts/contracts/client/add-reservations/src/main.rs b/smart_contracts/contracts/client/add-reservations/src/main.rs new file mode 100644 index 0000000000..cc32877143 --- /dev/null +++ b/smart_contracts/contracts/client/add-reservations/src/main.rs @@ -0,0 +1,35 @@ +#![no_std] +#![no_main] + +extern crate alloc; + +use alloc::vec::Vec; + +use casper_contract::contract_api::{runtime, system}; +use casper_types::{runtime_args, system::auction, PublicKey, U512}; + +const ARG_VALIDATOR: &str = "validator"; +const ARG_DELEGATORS: &str = "delegators"; + +fn add_reservations(validator: PublicKey, delegators: &[PublicKey]) { + let contract_hash = system::get_auction(); + for delegator in delegators { + let args = runtime_args! { + auction::ARG_DELEGATOR => delegator, + auction::ARG_VALIDATOR => validator.clone(), + }; + runtime::call_contract::(contract_hash, auction::METHOD_ADD_RESERVATION, args); + } +} + +// Add delegators to validator's reserved list. +// +// Accepts delegators' and validator's public keys. +// Issues an add_reservation request to the auction contract. +#[no_mangle] +pub extern "C" fn call() { + let delegators: Vec = runtime::get_named_arg(ARG_DELEGATORS); + let validator = runtime::get_named_arg(ARG_VALIDATOR); + + add_reservations(validator, &delegators); +} diff --git a/smart_contracts/contracts/client/cancel-reservation/src/main.rs b/smart_contracts/contracts/client/cancel-reservation/src/main.rs deleted file mode 100644 index f5d45da78e..0000000000 --- a/smart_contracts/contracts/client/cancel-reservation/src/main.rs +++ /dev/null @@ -1,31 +0,0 @@ -#![no_std] -#![no_main] - -extern crate alloc; - -use casper_contract::contract_api::{runtime, system}; -use casper_types::{runtime_args, system::auction, PublicKey, U512}; - -const ARG_VALIDATOR: &str = "validator"; -const ARG_DELEGATOR: &str = "delegator"; - -fn cancel_reservation(delegator: PublicKey, validator: PublicKey) { - let contract_hash = system::get_auction(); - let args = runtime_args! { - auction::ARG_DELEGATOR => delegator, - auction::ARG_VALIDATOR => validator, - }; - runtime::call_contract::(contract_hash, auction::METHOD_CANCEL_RESERVATION, args); -} - -// Remove delegator from validator's reserved list. -// -// Accepts delegator's and validator's public keys. -// Issues a cancel_reservation request to the auction contract. -#[no_mangle] -pub extern "C" fn call() { - let delegator = runtime::get_named_arg(ARG_DELEGATOR); - let validator = runtime::get_named_arg(ARG_VALIDATOR); - - cancel_reservation(delegator, validator); -} diff --git a/smart_contracts/contracts/client/cancel-reservation/Cargo.toml b/smart_contracts/contracts/client/cancel-reservations/Cargo.toml similarity index 83% rename from smart_contracts/contracts/client/cancel-reservation/Cargo.toml rename to smart_contracts/contracts/client/cancel-reservations/Cargo.toml index eca418a7a3..4397a2dcb9 100644 --- a/smart_contracts/contracts/client/cancel-reservation/Cargo.toml +++ b/smart_contracts/contracts/client/cancel-reservations/Cargo.toml @@ -1,11 +1,11 @@ [package] -name = "cancel-reservation" +name = "cancel-reservations" version = "0.1.0" authors = ["Jacek Chmielewski "] edition = "2021" [[bin]] -name = "cancel_reservation" +name = "cancel_reservations" path = "src/main.rs" bench = false doctest = false diff --git a/smart_contracts/contracts/client/cancel-reservations/src/main.rs b/smart_contracts/contracts/client/cancel-reservations/src/main.rs new file mode 100644 index 0000000000..c9ff94a517 --- /dev/null +++ b/smart_contracts/contracts/client/cancel-reservations/src/main.rs @@ -0,0 +1,35 @@ +#![no_std] +#![no_main] + +extern crate alloc; + +use alloc::vec::Vec; + +use casper_contract::contract_api::{runtime, system}; +use casper_types::{runtime_args, system::auction, PublicKey, U512}; + +const ARG_VALIDATOR: &str = "validator"; +const ARG_DELEGATORS: &str = "delegators"; + +fn cancel_reservations(validator: PublicKey, delegators: &[PublicKey]) { + let contract_hash = system::get_auction(); + for delegator in delegators { + let args = runtime_args! { + auction::ARG_DELEGATOR => delegator, + auction::ARG_VALIDATOR => validator.clone(), + }; + runtime::call_contract::(contract_hash, auction::METHOD_CANCEL_RESERVATION, args); + } +} + +// Remove delegators from validator's reserved list. +// +// Accepts delegators' and validator's public keys. +// Issues a cancel_reservation request to the auction contract. +#[no_mangle] +pub extern "C" fn call() { + let delegators: Vec = runtime::get_named_arg(ARG_DELEGATORS); + let validator = runtime::get_named_arg(ARG_VALIDATOR); + + cancel_reservations(validator, &delegators); +} From 5003f03908f82152f7ee4404feb529f6d9fb2147 Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Thu, 11 Jul 2024 16:57:27 +0200 Subject: [PATCH 20/38] Stub add/cancel reservations smart contracts --- .../contracts/client/add-reservations/src/main.rs | 15 +++------------ .../client/cancel-reservations/src/main.rs | 15 +++------------ types/src/system/auction/constants.rs | 2 ++ 3 files changed, 8 insertions(+), 24 deletions(-) diff --git a/smart_contracts/contracts/client/add-reservations/src/main.rs b/smart_contracts/contracts/client/add-reservations/src/main.rs index cc32877143..bf85a9d3ca 100644 --- a/smart_contracts/contracts/client/add-reservations/src/main.rs +++ b/smart_contracts/contracts/client/add-reservations/src/main.rs @@ -8,18 +8,9 @@ use alloc::vec::Vec; use casper_contract::contract_api::{runtime, system}; use casper_types::{runtime_args, system::auction, PublicKey, U512}; -const ARG_VALIDATOR: &str = "validator"; -const ARG_DELEGATORS: &str = "delegators"; fn add_reservations(validator: PublicKey, delegators: &[PublicKey]) { - let contract_hash = system::get_auction(); - for delegator in delegators { - let args = runtime_args! { - auction::ARG_DELEGATOR => delegator, - auction::ARG_VALIDATOR => validator.clone(), - }; - runtime::call_contract::(contract_hash, auction::METHOD_ADD_RESERVATION, args); - } + todo!(); } // Add delegators to validator's reserved list. @@ -28,8 +19,8 @@ fn add_reservations(validator: PublicKey, delegators: &[PublicKey]) { // Issues an add_reservation request to the auction contract. #[no_mangle] pub extern "C" fn call() { - let delegators: Vec = runtime::get_named_arg(ARG_DELEGATORS); - let validator = runtime::get_named_arg(ARG_VALIDATOR); + let delegators: Vec = runtime::get_named_arg(auction::ARG_DELEGATORS); + let validator = runtime::get_named_arg(auction::ARG_VALIDATOR); add_reservations(validator, &delegators); } diff --git a/smart_contracts/contracts/client/cancel-reservations/src/main.rs b/smart_contracts/contracts/client/cancel-reservations/src/main.rs index c9ff94a517..af721f57da 100644 --- a/smart_contracts/contracts/client/cancel-reservations/src/main.rs +++ b/smart_contracts/contracts/client/cancel-reservations/src/main.rs @@ -8,18 +8,9 @@ use alloc::vec::Vec; use casper_contract::contract_api::{runtime, system}; use casper_types::{runtime_args, system::auction, PublicKey, U512}; -const ARG_VALIDATOR: &str = "validator"; -const ARG_DELEGATORS: &str = "delegators"; fn cancel_reservations(validator: PublicKey, delegators: &[PublicKey]) { - let contract_hash = system::get_auction(); - for delegator in delegators { - let args = runtime_args! { - auction::ARG_DELEGATOR => delegator, - auction::ARG_VALIDATOR => validator.clone(), - }; - runtime::call_contract::(contract_hash, auction::METHOD_CANCEL_RESERVATION, args); - } + todo!(); } // Remove delegators from validator's reserved list. @@ -28,8 +19,8 @@ fn cancel_reservations(validator: PublicKey, delegators: &[PublicKey]) { // Issues a cancel_reservation request to the auction contract. #[no_mangle] pub extern "C" fn call() { - let delegators: Vec = runtime::get_named_arg(ARG_DELEGATORS); - let validator = runtime::get_named_arg(ARG_VALIDATOR); + let delegators: Vec = runtime::get_named_arg(auction::ARG_DELEGATORS); + let validator = runtime::get_named_arg(auction::ARG_VALIDATOR); cancel_reservations(validator, &delegators); } diff --git a/types/src/system/auction/constants.rs b/types/src/system/auction/constants.rs index 8f96645b25..135c9f5019 100644 --- a/types/src/system/auction/constants.rs +++ b/types/src/system/auction/constants.rs @@ -28,6 +28,8 @@ pub const ARG_NEW_PUBLIC_KEY: &str = "new_public_key"; pub const ARG_VALIDATOR: &str = "validator"; /// Named constant for `delegator`. pub const ARG_DELEGATOR: &str = "delegator"; +/// Named constant for `delegators`. +pub const ARG_DELEGATORS: &str = "delegators"; /// Named constant for `validator_purse`. pub const ARG_VALIDATOR_PURSE: &str = "validator_purse"; /// Named constant for `validator_keys`. From a97a3581e6b21677ca15852360825f55c34c7971 Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Thu, 11 Jul 2024 17:37:06 +0200 Subject: [PATCH 21/38] Rename reservation enums/structs/consts --- execution_engine/src/runtime/mod.rs | 4 +- node/src/components/transaction_acceptor.rs | 4 +- resources/local/chainspec.toml.in | 4 +- resources/production/chainspec.toml | 4 +- resources/test/sse_data_schema.json | 8 +-- .../client/add-reservations/src/main.rs | 2 +- .../client/cancel-reservations/src/main.rs | 2 +- storage/src/data_access_layer/auction.rs | 2 +- .../src/chainspec/vm_config/auction_costs.rs | 56 +++++++++---------- types/src/system/auction/constants.rs | 8 +-- .../transaction/transaction_entry_point.rs | 36 ++++++------ types/src/transaction/transaction_v1.rs | 8 +-- .../transaction_v1/transaction_v1_body.rs | 12 ++-- 13 files changed, 75 insertions(+), 75 deletions(-) diff --git a/execution_engine/src/runtime/mod.rs b/execution_engine/src/runtime/mod.rs index bbd5aebac5..c259ccc73c 100644 --- a/execution_engine/src/runtime/mod.rs +++ b/execution_engine/src/runtime/mod.rs @@ -1125,8 +1125,8 @@ where CLValue::from_t(()).map_err(Self::reverter) })(), - auction::METHOD_ADD_RESERVATION => todo!(), - auction::METHOD_CANCEL_RESERVATION => todo!(), + auction::METHOD_ADD_RESERVATIONS => todo!(), + auction::METHOD_CANCEL_RESERVATIONS => todo!(), _ => CLValue::from_t(()).map_err(Self::reverter), }; diff --git a/node/src/components/transaction_acceptor.rs b/node/src/components/transaction_acceptor.rs index 2d5339eb4e..3897df6adf 100644 --- a/node/src/components/transaction_acceptor.rs +++ b/node/src/components/transaction_acceptor.rs @@ -579,8 +579,8 @@ impl TransactionAcceptor { | TransactionEntryPoint::Redelegate | TransactionEntryPoint::ActivateBid | TransactionEntryPoint::ChangeBidPublicKey - | TransactionEntryPoint::AddReservation - | TransactionEntryPoint::CancelReservation => None + | TransactionEntryPoint::AddReservations + | TransactionEntryPoint::CancelReservations => None }, }; diff --git a/resources/local/chainspec.toml.in b/resources/local/chainspec.toml.in index e87b848a08..6883bdce17 100644 --- a/resources/local/chainspec.toml.in +++ b/resources/local/chainspec.toml.in @@ -341,8 +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_reservation = 2_500_000_000 -cancel_reservation = 2_500_000_000 +add_reservations = 2_500_000_000 +cancel_reservations = 2_500_000_000 [system_costs.mint_costs] mint = 2_500_000_000 diff --git a/resources/production/chainspec.toml b/resources/production/chainspec.toml index 6eae3f9528..5476c2c439 100644 --- a/resources/production/chainspec.toml +++ b/resources/production/chainspec.toml @@ -351,8 +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_reservation = 2_500_000_000 -cancel_reservation = 2_500_000_000 +add_reservations = 2_500_000_000 +cancel_reservations = 2_500_000_000 [system_costs.mint_costs] mint = 2_500_000_000 diff --git a/resources/test/sse_data_schema.json b/resources/test/sse_data_schema.json index 1d9cd15621..c4d5f34b8d 100644 --- a/resources/test/sse_data_schema.json +++ b/resources/test/sse_data_schema.json @@ -2055,17 +2055,17 @@ ] }, { - "description": "The `add_reservation` native entry point, used to add delegator to validator's reserve list", + "description": "The `add_reservations` native entry point, used to add delegator to validator's reserve list", "type": "string", "enum": [ - "AddReservation" + "AddReservations" ] }, { - "description": "The `cancel_reservation` native entry point, used to remove delegator from validator's reserve list", + "description": "The `cancel_reservations` native entry point, used to remove delegator from validator's reserve list", "type": "string", "enum": [ - "CancelReservation" + "CancelReservations" ] } ] diff --git a/smart_contracts/contracts/client/add-reservations/src/main.rs b/smart_contracts/contracts/client/add-reservations/src/main.rs index bf85a9d3ca..c2501aea4e 100644 --- a/smart_contracts/contracts/client/add-reservations/src/main.rs +++ b/smart_contracts/contracts/client/add-reservations/src/main.rs @@ -16,7 +16,7 @@ fn add_reservations(validator: PublicKey, delegators: &[PublicKey]) { // Add delegators to validator's reserved list. // // Accepts delegators' and validator's public keys. -// Issues an add_reservation request to the auction contract. +// Issues an add_reservations request to the auction contract. #[no_mangle] pub extern "C" fn call() { let delegators: Vec = runtime::get_named_arg(auction::ARG_DELEGATORS); diff --git a/smart_contracts/contracts/client/cancel-reservations/src/main.rs b/smart_contracts/contracts/client/cancel-reservations/src/main.rs index af721f57da..8458b3e66e 100644 --- a/smart_contracts/contracts/client/cancel-reservations/src/main.rs +++ b/smart_contracts/contracts/client/cancel-reservations/src/main.rs @@ -16,7 +16,7 @@ fn cancel_reservations(validator: PublicKey, delegators: &[PublicKey]) { // Remove delegators from validator's reserved list. // // Accepts delegators' and validator's public keys. -// Issues a cancel_reservation request to the auction contract. +// Issues a cancel_reservations request to the auction contract. #[no_mangle] pub extern "C" fn call() { let delegators: Vec = runtime::get_named_arg(auction::ARG_DELEGATORS); diff --git a/storage/src/data_access_layer/auction.rs b/storage/src/data_access_layer/auction.rs index 5910c9c4a7..24818fa7bf 100644 --- a/storage/src/data_access_layer/auction.rs +++ b/storage/src/data_access_layer/auction.rs @@ -103,7 +103,7 @@ impl AuctionMethod { TransactionEntryPoint::ChangeBidPublicKey => { Self::new_change_bid_public_key(runtime_args) } - TransactionEntryPoint::AddReservation | TransactionEntryPoint::CancelReservation => { + TransactionEntryPoint::AddReservations | TransactionEntryPoint::CancelReservations => { todo!() } } diff --git a/types/src/chainspec/vm_config/auction_costs.rs b/types/src/chainspec/vm_config/auction_costs.rs index 8f6cb7b181..d46fb9e6c8 100644 --- a/types/src/chainspec/vm_config/auction_costs.rs +++ b/types/src/chainspec/vm_config/auction_costs.rs @@ -40,10 +40,10 @@ pub const DEFAULT_READ_ERA_ID_COST: u32 = 10_000; pub const DEFAULT_ACTIVATE_BID_COST: u32 = 10_000; /// Default cost of the `change_bid_public_key` auction entry point. pub const DEFAULT_CHANGE_BID_PUBLIC_KEY_COST: u64 = 5_000_000_000; -/// Default cost of the `add_reservation` auction entry point. -pub const DEFAULT_ADD_RESERVATION_COST: u32 = DEFAULT_ADD_BID_COST; -/// Default cost of the `cancel_reservation` auction entry point. -pub const DEFAULT_CANCEL_RESERVATION_COST: u32 = DEFAULT_ADD_BID_COST; +/// Default cost of the `add_reservations` auction entry point. +pub const DEFAULT_ADD_RESERVATIONS_COST: u32 = DEFAULT_ADD_BID_COST; +/// Default cost of the `cancel_reservations` auction entry point. +pub const DEFAULT_CANCEL_RESERVATIONS_COST: u32 = DEFAULT_ADD_BID_COST; /// Description of the costs of calling auction entrypoints. #[derive(Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Debug)] @@ -80,10 +80,10 @@ pub struct AuctionCosts { pub redelegate: u32, /// Cost of calling the `change_bid_public_key` entry point. pub change_bid_public_key: u64, - /// Cost of calling the `add_reservation` entry point. - pub add_reservation: u32, - /// Cost of calling the `cancel_reservation` entry point. - pub cancel_reservation: u32, + /// Cost of calling the `add_reservations` entry point. + pub add_reservations: u32, + /// Cost of calling the `cancel_reservations` entry point. + pub cancel_reservations: u32, } impl Default for AuctionCosts { @@ -104,8 +104,8 @@ impl Default for AuctionCosts { activate_bid: DEFAULT_ACTIVATE_BID_COST, redelegate: DEFAULT_REDELEGATE_COST, change_bid_public_key: DEFAULT_CHANGE_BID_PUBLIC_KEY_COST, - add_reservation: DEFAULT_ADD_RESERVATION_COST, - cancel_reservation: DEFAULT_CANCEL_RESERVATION_COST, + add_reservations: DEFAULT_ADD_RESERVATIONS_COST, + cancel_reservations: DEFAULT_CANCEL_RESERVATIONS_COST, } } } @@ -130,8 +130,8 @@ impl ToBytes for AuctionCosts { activate_bid, redelegate, change_bid_public_key, - add_reservation, - cancel_reservation, + add_reservations, + cancel_reservations, } = self; ret.append(&mut get_era_validators.to_bytes()?); @@ -149,8 +149,8 @@ impl ToBytes for AuctionCosts { ret.append(&mut activate_bid.to_bytes()?); ret.append(&mut redelegate.to_bytes()?); ret.append(&mut change_bid_public_key.to_bytes()?); - ret.append(&mut add_reservation.to_bytes()?); - ret.append(&mut cancel_reservation.to_bytes()?); + ret.append(&mut add_reservations.to_bytes()?); + ret.append(&mut cancel_reservations.to_bytes()?); Ok(ret) } @@ -172,8 +172,8 @@ impl ToBytes for AuctionCosts { activate_bid, redelegate, change_bid_public_key, - add_reservation, - cancel_reservation, + add_reservations, + cancel_reservations, } = self; get_era_validators.serialized_length() @@ -191,8 +191,8 @@ impl ToBytes for AuctionCosts { + activate_bid.serialized_length() + redelegate.serialized_length() + change_bid_public_key.serialized_length() - + add_reservation.serialized_length() - + cancel_reservation.serialized_length() + + add_reservations.serialized_length() + + cancel_reservations.serialized_length() } } @@ -213,8 +213,8 @@ impl FromBytes for AuctionCosts { let (activate_bid, rem) = FromBytes::from_bytes(rem)?; let (redelegate, rem) = FromBytes::from_bytes(rem)?; let (change_bid_public_key, rem) = FromBytes::from_bytes(rem)?; - let (add_reservation, rem) = FromBytes::from_bytes(rem)?; - let (cancel_reservation, rem) = FromBytes::from_bytes(rem)?; + let (add_reservations, rem) = FromBytes::from_bytes(rem)?; + let (cancel_reservations, rem) = FromBytes::from_bytes(rem)?; Ok(( Self { get_era_validators, @@ -232,8 +232,8 @@ impl FromBytes for AuctionCosts { activate_bid, redelegate, change_bid_public_key, - add_reservation, - cancel_reservation, + add_reservations, + cancel_reservations, }, rem, )) @@ -263,8 +263,8 @@ impl Distribution for Standard { activate_bid: rng.gen(), redelegate: rng.gen(), change_bid_public_key, - add_reservation: rng.gen(), - cancel_reservation: rng.gen(), + add_reservations: rng.gen(), + cancel_reservations: rng.gen(), } } } @@ -293,8 +293,8 @@ pub mod gens { activate_bid in num::u32::ANY, redelegate in num::u32::ANY, change_bid_public_key in num::u64::ANY, - add_reservation in num::u32::ANY, - cancel_reservation in num::u32::ANY, + add_reservations in num::u32::ANY, + cancel_reservations in num::u32::ANY, ) -> AuctionCosts { AuctionCosts { get_era_validators, @@ -312,8 +312,8 @@ pub mod gens { activate_bid, redelegate, change_bid_public_key, - add_reservation, - cancel_reservation, + add_reservations, + cancel_reservations, } } } diff --git a/types/src/system/auction/constants.rs b/types/src/system/auction/constants.rs index 135c9f5019..27edc0a506 100644 --- a/types/src/system/auction/constants.rs +++ b/types/src/system/auction/constants.rs @@ -91,10 +91,10 @@ pub const METHOD_READ_ERA_ID: &str = "read_era_id"; pub const METHOD_ACTIVATE_BID: &str = "activate_bid"; /// Named constant for method `change_bid_public_key`. pub const METHOD_CHANGE_BID_PUBLIC_KEY: &str = " change_bid_public_key"; -/// Named constant for method `add_reservation`. -pub const METHOD_ADD_RESERVATION: &str = "add_reservation"; -/// Named constant for method `cancel_reservation`. -pub const METHOD_CANCEL_RESERVATION: &str = "cancel_reservation"; +/// Named constant for method `add_reservations`. +pub const METHOD_ADD_RESERVATIONS: &str = "add_reservations"; +/// Named constant for method `cancel_reservations`. +pub const METHOD_CANCEL_RESERVATIONS: &str = "cancel_reservations"; /// Storage for `EraId`. pub const ERA_ID_KEY: &str = "era_id"; diff --git a/types/src/transaction/transaction_entry_point.rs b/types/src/transaction/transaction_entry_point.rs index 38ec8752f8..aeb33fda08 100644 --- a/types/src/transaction/transaction_entry_point.rs +++ b/types/src/transaction/transaction_entry_point.rs @@ -29,8 +29,8 @@ const REDELEGATE_TAG: u8 = 6; const ACTIVATE_BID_TAG: u8 = 7; const CHANGE_BID_PUBLIC_KEY_TAG: u8 = 8; const CALL_TAG: u8 = 9; -const ADD_RESERVATION_TAG: u8 = 10; -const CANCEL_RESERVATION_TAG: u8 = 11; +const ADD_RESERVATIONS_TAG: u8 = 10; +const CANCEL_RESERVATIONS_TAG: u8 = 11; /// The entry point of a [`Transaction`]. #[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Serialize, Deserialize, Debug)] @@ -167,34 +167,34 @@ pub enum TransactionEntryPoint { ) )] ChangeBidPublicKey, - /// The `add_reservation` native entry point, used to add delegator to validator's reserve + /// The `add_reservations` native entry point, used to add delegators to validator's reserve /// list. /// /// Requires the following runtime args: - /// * "delegator": `PublicKey` /// * "validator": `PublicKey` + /// * "delegators": `&[PublicKey]` #[cfg_attr( feature = "json-schema", schemars( - description = "The `add_reservation` native entry point, used to add delegator to \ + description = "The `add_reservations` native entry point, used to add delegator to \ validator's reserve list" ) )] - AddReservation, - /// The `cancel_reservation` native entry point, used to remove delegator from validator's + AddReservations, + /// The `cancel_reservations` native entry point, used to remove delegators from validator's /// reserve list. /// /// Requires the following runtime args: - /// * "delegator": `PublicKey` /// * "validator": `PublicKey` + /// * "delegator": `&[PublicKey]` #[cfg_attr( feature = "json-schema", schemars( - description = "The `cancel_reservation` native entry point, used to remove delegator \ + description = "The `cancel_reservations` native entry point, used to remove delegator \ from validator's reserve list" ) )] - CancelReservation, + CancelReservations, } impl TransactionEntryPoint { @@ -229,8 +229,8 @@ impl TransactionEntryPoint { | TransactionEntryPoint::Redelegate | TransactionEntryPoint::ActivateBid | TransactionEntryPoint::ChangeBidPublicKey - | TransactionEntryPoint::AddReservation - | TransactionEntryPoint::CancelReservation => false + | TransactionEntryPoint::AddReservations + | TransactionEntryPoint::CancelReservations => false } } } @@ -250,8 +250,8 @@ impl Display for TransactionEntryPoint { TransactionEntryPoint::Redelegate => write!(formatter, "redelegate"), TransactionEntryPoint::ActivateBid => write!(formatter, "activate_bid"), TransactionEntryPoint::ChangeBidPublicKey => write!(formatter, "change_bid_public_key"), - TransactionEntryPoint::AddReservation => write!(formatter, "add_reservation"), - TransactionEntryPoint::CancelReservation => write!(formatter, "cancel_reservation"), + TransactionEntryPoint::AddReservations => write!(formatter, "add_reservations"), + TransactionEntryPoint::CancelReservations => write!(formatter, "cancel_reservations"), } } } @@ -274,8 +274,8 @@ impl ToBytes for TransactionEntryPoint { TransactionEntryPoint::ChangeBidPublicKey => { CHANGE_BID_PUBLIC_KEY_TAG.write_bytes(writer) }, - TransactionEntryPoint::AddReservation => ADD_RESERVATION_TAG.write_bytes(writer), - TransactionEntryPoint::CancelReservation=> CANCEL_RESERVATION_TAG.write_bytes(writer), + TransactionEntryPoint::AddReservations => ADD_RESERVATIONS_TAG.write_bytes(writer), + TransactionEntryPoint::CancelReservations => CANCEL_RESERVATIONS_TAG.write_bytes(writer), } } @@ -298,8 +298,8 @@ impl ToBytes for TransactionEntryPoint { | TransactionEntryPoint::Redelegate | TransactionEntryPoint::ActivateBid | TransactionEntryPoint::ChangeBidPublicKey - | TransactionEntryPoint::AddReservation - | TransactionEntryPoint::CancelReservation => 0 + | TransactionEntryPoint::AddReservations + | TransactionEntryPoint::CancelReservations => 0 } } } diff --git a/types/src/transaction/transaction_v1.rs b/types/src/transaction/transaction_v1.rs index ecfe189a18..a3ac1e46fe 100644 --- a/types/src/transaction/transaction_v1.rs +++ b/types/src/transaction/transaction_v1.rs @@ -645,11 +645,11 @@ impl GasLimited for TransactionV1 { TransactionEntryPoint::ChangeBidPublicKey => { costs.auction_costs().change_bid_public_key } - TransactionEntryPoint::AddReservation => { - costs.auction_costs().add_reservation.into() + TransactionEntryPoint::AddReservations => { + costs.auction_costs().add_reservations.into() } - TransactionEntryPoint::CancelReservation => { - costs.auction_costs().cancel_reservation.into() + TransactionEntryPoint::CancelReservations => { + costs.auction_costs().cancel_reservations.into() } }; amount diff --git a/types/src/transaction/transaction_v1/transaction_v1_body.rs b/types/src/transaction/transaction_v1/transaction_v1_body.rs index 6eaba9df55..09fc739c2d 100644 --- a/types/src/transaction/transaction_v1/transaction_v1_body.rs +++ b/types/src/transaction/transaction_v1/transaction_v1_body.rs @@ -207,10 +207,10 @@ impl TransactionV1Body { TransactionEntryPoint::ChangeBidPublicKey => { arg_handling::has_valid_change_bid_public_key_args(&self.args) } - TransactionEntryPoint::AddReservation => { + TransactionEntryPoint::AddReservations => { todo!() } - TransactionEntryPoint::CancelReservation => { + TransactionEntryPoint::CancelReservations => { todo!() } }, @@ -225,8 +225,8 @@ impl TransactionV1Body { | TransactionEntryPoint::Redelegate | TransactionEntryPoint::ActivateBid | TransactionEntryPoint::ChangeBidPublicKey - | TransactionEntryPoint::AddReservation - | TransactionEntryPoint::CancelReservation => { + | TransactionEntryPoint::AddReservations + | TransactionEntryPoint::CancelReservations => { debug!( entry_point = %self.entry_point, "transaction targeting stored entity/package must have custom entry point" @@ -252,8 +252,8 @@ impl TransactionV1Body { | TransactionEntryPoint::Redelegate | TransactionEntryPoint::ActivateBid | TransactionEntryPoint::ChangeBidPublicKey - | TransactionEntryPoint::AddReservation - | TransactionEntryPoint::CancelReservation => { + | TransactionEntryPoint::AddReservations + | TransactionEntryPoint::CancelReservations => { debug!( entry_point = %self.entry_point, "transaction with session code must use custom or default 'call' entry point" From 05ee41abe22de54a2d189f06316f9c73565be26f Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Thu, 11 Jul 2024 17:54:42 +0200 Subject: [PATCH 22/38] Fix entry point arg name --- types/src/transaction/transaction_entry_point.rs | 2 +- utils/validation/tests/fixtures/ABI/stored_value.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/types/src/transaction/transaction_entry_point.rs b/types/src/transaction/transaction_entry_point.rs index aeb33fda08..fb31699793 100644 --- a/types/src/transaction/transaction_entry_point.rs +++ b/types/src/transaction/transaction_entry_point.rs @@ -186,7 +186,7 @@ pub enum TransactionEntryPoint { /// /// Requires the following runtime args: /// * "validator": `PublicKey` - /// * "delegator": `&[PublicKey]` + /// * "delegators": `&[PublicKey]` #[cfg_attr( feature = "json-schema", schemars( diff --git a/utils/validation/tests/fixtures/ABI/stored_value.json b/utils/validation/tests/fixtures/ABI/stored_value.json index e3663fd9cd..d91070c7e2 100644 --- a/utils/validation/tests/fixtures/ABI/stored_value.json +++ b/utils/validation/tests/fixtures/ABI/stored_value.json @@ -407,4 +407,4 @@ ], "output": "09020000000a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0101197f6b23e16c8532c6abc838facd5ea789be0c76b2920334039bfa8b3d368d6101197f6b23e16c8532c6abc838facd5ea789be0c76b2920334039bfa8b3d368d61290000000000000005005847f80d0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0101197f6b23e16c8532c6abc838facd5ea789be0c76b2920334039bfa8b3d368d610202bb58b5feca505c74edc000d8282fc556e51a1024fc8e7d7e56c6f887c5c8d5f22a000000000000000500743ba40b" } -} \ No newline at end of file +} From 4f2a3b7ed937e8c1515c0a9ccce6fbdbb562151e Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Fri, 12 Jul 2024 11:16:22 +0200 Subject: [PATCH 23/38] Cargo fmt --- execution_engine/src/runtime/mod.rs | 8 +++----- node/src/components/transaction_acceptor.rs | 2 +- smart_contracts/contracts/client/add-bid/src/main.rs | 5 +---- .../contracts/client/add-reservations/src/main.rs | 7 +++---- .../contracts/client/cancel-reservations/src/main.rs | 7 +++---- types/src/system/auction/bid_addr.rs | 5 ++++- types/src/transaction/transaction_entry_point.rs | 10 ++++++---- 7 files changed, 21 insertions(+), 23 deletions(-) diff --git a/execution_engine/src/runtime/mod.rs b/execution_engine/src/runtime/mod.rs index c259ccc73c..f24d39f653 100644 --- a/execution_engine/src/runtime/mod.rs +++ b/execution_engine/src/runtime/mod.rs @@ -968,11 +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 reserved_slots = + Self::try_get_named_argument(runtime_args, auction::ARG_RESERVED_SLOTS)? + .unwrap_or(0); let result = runtime .add_bid( diff --git a/node/src/components/transaction_acceptor.rs b/node/src/components/transaction_acceptor.rs index 3897df6adf..8abbf5b67f 100644 --- a/node/src/components/transaction_acceptor.rs +++ b/node/src/components/transaction_acceptor.rs @@ -580,7 +580,7 @@ impl TransactionAcceptor { | TransactionEntryPoint::ActivateBid | TransactionEntryPoint::ChangeBidPublicKey | TransactionEntryPoint::AddReservations - | TransactionEntryPoint::CancelReservations => None + | TransactionEntryPoint::CancelReservations => None, }, }; diff --git a/smart_contracts/contracts/client/add-bid/src/main.rs b/smart_contracts/contracts/client/add-bid/src/main.rs index 15c8d53e64..bd0faaa490 100644 --- a/smart_contracts/contracts/client/add-bid/src/main.rs +++ b/smart_contracts/contracts/client/add-bid/src/main.rs @@ -90,10 +90,7 @@ fn add_bid( ); } if let Some(reserved_slots) = reserved_slots { - let _ = args.insert( - auction::ARG_RESERVED_SLOTS, - reserved_slots, - ); + let _ = args.insert(auction::ARG_RESERVED_SLOTS, reserved_slots); } runtime::call_contract::(contract_hash, auction::METHOD_ADD_BID, args); } diff --git a/smart_contracts/contracts/client/add-reservations/src/main.rs b/smart_contracts/contracts/client/add-reservations/src/main.rs index c2501aea4e..ec68088763 100644 --- a/smart_contracts/contracts/client/add-reservations/src/main.rs +++ b/smart_contracts/contracts/client/add-reservations/src/main.rs @@ -5,11 +5,10 @@ extern crate alloc; use alloc::vec::Vec; -use casper_contract::contract_api::{runtime, system}; -use casper_types::{runtime_args, system::auction, PublicKey, U512}; +use casper_contract::contract_api::runtime; +use casper_types::{system::auction, PublicKey}; - -fn add_reservations(validator: PublicKey, delegators: &[PublicKey]) { +fn add_reservations(_validator: PublicKey, _delegators: &[PublicKey]) { todo!(); } diff --git a/smart_contracts/contracts/client/cancel-reservations/src/main.rs b/smart_contracts/contracts/client/cancel-reservations/src/main.rs index 8458b3e66e..eddd320c6e 100644 --- a/smart_contracts/contracts/client/cancel-reservations/src/main.rs +++ b/smart_contracts/contracts/client/cancel-reservations/src/main.rs @@ -5,11 +5,10 @@ extern crate alloc; use alloc::vec::Vec; -use casper_contract::contract_api::{runtime, system}; -use casper_types::{runtime_args, system::auction, PublicKey, U512}; +use casper_contract::contract_api::runtime; +use casper_types::{system::auction, PublicKey}; - -fn cancel_reservations(validator: PublicKey, delegators: &[PublicKey]) { +fn cancel_reservations(_validator: PublicKey, _delegators: &[PublicKey]) { todo!(); } diff --git a/types/src/system/auction/bid_addr.rs b/types/src/system/auction/bid_addr.rs index b043cfffb9..65eca7c819 100644 --- a/types/src/system/auction/bid_addr.rs +++ b/types/src/system/auction/bid_addr.rs @@ -221,7 +221,10 @@ impl BidAddr { /// Else, it is the key for a validator bid record. pub fn is_delegator_bid_addr(&self) -> bool { match self { - BidAddr::Unified(_) | BidAddr::Validator(_) | BidAddr::Credit { .. } | BidAddr::Reservation { .. } => false, + BidAddr::Unified(_) + | BidAddr::Validator(_) + | BidAddr::Credit { .. } + | BidAddr::Reservation { .. } => false, BidAddr::Delegator { .. } => true, } } diff --git a/types/src/transaction/transaction_entry_point.rs b/types/src/transaction/transaction_entry_point.rs index fb31699793..0ed1a575b2 100644 --- a/types/src/transaction/transaction_entry_point.rs +++ b/types/src/transaction/transaction_entry_point.rs @@ -230,7 +230,7 @@ impl TransactionEntryPoint { | TransactionEntryPoint::ActivateBid | TransactionEntryPoint::ChangeBidPublicKey | TransactionEntryPoint::AddReservations - | TransactionEntryPoint::CancelReservations => false + | TransactionEntryPoint::CancelReservations => false, } } } @@ -273,9 +273,11 @@ impl ToBytes for TransactionEntryPoint { TransactionEntryPoint::ActivateBid => ACTIVATE_BID_TAG.write_bytes(writer), TransactionEntryPoint::ChangeBidPublicKey => { CHANGE_BID_PUBLIC_KEY_TAG.write_bytes(writer) - }, + } TransactionEntryPoint::AddReservations => ADD_RESERVATIONS_TAG.write_bytes(writer), - TransactionEntryPoint::CancelReservations => CANCEL_RESERVATIONS_TAG.write_bytes(writer), + TransactionEntryPoint::CancelReservations => { + CANCEL_RESERVATIONS_TAG.write_bytes(writer) + } } } @@ -299,7 +301,7 @@ impl ToBytes for TransactionEntryPoint { | TransactionEntryPoint::ActivateBid | TransactionEntryPoint::ChangeBidPublicKey | TransactionEntryPoint::AddReservations - | TransactionEntryPoint::CancelReservations => 0 + | TransactionEntryPoint::CancelReservations => 0, } } } From 1d7127b3622957830c7c80e56fbf9f5fec7c756f Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Fri, 12 Jul 2024 12:35:15 +0200 Subject: [PATCH 24/38] Add reservation auction costs to testing chainspecs --- resources/test/valid/0_9_0/chainspec.toml | 2 ++ resources/test/valid/0_9_0_unordered/chainspec.toml | 2 ++ resources/test/valid/1_0_0/chainspec.toml | 2 ++ 3 files changed, 6 insertions(+) diff --git a/resources/test/valid/0_9_0/chainspec.toml b/resources/test/valid/0_9_0/chainspec.toml index e419cf51f6..75534c2625 100644 --- a/resources/test/valid/0_9_0/chainspec.toml +++ b/resources/test/valid/0_9_0/chainspec.toml @@ -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 diff --git a/resources/test/valid/0_9_0_unordered/chainspec.toml b/resources/test/valid/0_9_0_unordered/chainspec.toml index f82ac44579..438a97672d 100644 --- a/resources/test/valid/0_9_0_unordered/chainspec.toml +++ b/resources/test/valid/0_9_0_unordered/chainspec.toml @@ -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 diff --git a/resources/test/valid/1_0_0/chainspec.toml b/resources/test/valid/1_0_0/chainspec.toml index e23b40499d..5e3086a9dc 100644 --- a/resources/test/valid/1_0_0/chainspec.toml +++ b/resources/test/valid/1_0_0/chainspec.toml @@ -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 From d3dd514b4c23701542a2cd0937f793396efe5cb1 Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Mon, 15 Jul 2024 11:36:17 +0200 Subject: [PATCH 25/38] Add Reservation type, BidKind, BidKindTag enum variants --- types/src/gens.rs | 10 +- types/src/system/auction.rs | 36 ++++- types/src/system/auction/bid_addr.rs | 8 ++ types/src/system/auction/bid_kind.rs | 47 +++++-- types/src/system/auction/reservation.rs | 127 ++++++++++++++++++ utils/global-state-update-gen/src/generic.rs | 10 +- .../src/generic/state_tracker.rs | 10 ++ 7 files changed, 234 insertions(+), 14 deletions(-) create mode 100644 types/src/system/auction/reservation.rs diff --git a/types/src/gens.rs b/types/src/gens.rs index ca754a988d..74673d9ad9 100644 --- a/types/src/gens.rs +++ b/types/src/gens.rs @@ -39,8 +39,9 @@ use crate::{ package::{EntityVersionKey, EntityVersions, Groups, PackageStatus}, system::{ auction::{ - gens::era_info_arb, Bid, BidAddr, BidKind, DelegationRate, Delegator, UnbondingPurse, - ValidatorBid, ValidatorCredit, WithdrawPurse, DELEGATION_RATE_DENOMINATOR, + gens::era_info_arb, Bid, BidAddr, BidKind, DelegationRate, Delegator, Reservation, + UnbondingPurse, ValidatorBid, ValidatorCredit, WithdrawPurse, + DELEGATION_RATE_DENOMINATOR, }, mint::BalanceHoldAddr, SystemEntityType, @@ -633,6 +634,11 @@ fn delegation_rate_arb() -> impl Strategy { 0..=DELEGATION_RATE_DENOMINATOR // Maximum, allowed value for delegation rate. } +pub(crate) fn reservation_arb() -> impl Strategy { + (public_key_arb_no_system(), public_key_arb_no_system()) + .prop_map(|(delegator_pk, validator_pk)| Reservation::new(delegator_pk, validator_pk)) +} + pub(crate) fn unified_bid_arb( delegations_len: impl Into, ) -> impl Strategy { diff --git a/types/src/system/auction.rs b/types/src/system/auction.rs index 54b55afa31..320d48a50a 100644 --- a/types/src/system/auction.rs +++ b/types/src/system/auction.rs @@ -8,6 +8,7 @@ mod delegator; mod entry_points; mod era_info; mod error; +mod reservation; mod seigniorage_recipient; mod unbonding_purse; mod validator_bid; @@ -30,6 +31,7 @@ pub use delegator::Delegator; pub use entry_points::auction_entry_points; pub use era_info::{EraInfo, SeigniorageAllocation}; pub use error::Error; +pub use reservation::Reservation; pub use seigniorage_recipient::SeigniorageRecipient; pub use unbonding_purse::UnbondingPurse; pub use validator_bid::ValidatorBid; @@ -109,6 +111,13 @@ pub trait BidsExt { delegator_public_key: &PublicKey, ) -> Option; + /// Returns Reservation entry by public keys, if present. + fn reservation_by_public_keys( + &self, + validator_public_key: &PublicKey, + delegator_public_key: &PublicKey, + ) -> Option; + /// Returns true if containing any elements matching the provided validator public key. fn contains_validator_public_key(&self, public_key: &PublicKey) -> bool; @@ -221,7 +230,8 @@ impl BidsExt for Vec { delegator_public_key: &PublicKey, ) -> Option { if let BidKind::Delegator(delegator) = self.iter().find(|x| { - &x.validator_public_key() == validator_public_key + x.is_delegator() + && &x.validator_public_key() == validator_public_key && x.delegator_public_key() == Some(delegator_public_key.clone()) })? { Some(*delegator.clone()) @@ -230,6 +240,22 @@ impl BidsExt for Vec { } } + fn reservation_by_public_keys( + &self, + validator_public_key: &PublicKey, + delegator_public_key: &PublicKey, + ) -> Option { + if let BidKind::Reservation(reservation) = self.iter().find(|x| { + x.is_reservation() + && &x.validator_public_key() == validator_public_key + && x.delegator_public_key() == Some(delegator_public_key.clone()) + })? { + Some(*reservation.clone()) + } else { + None + } + } + fn contains_validator_public_key(&self, public_key: &PublicKey) -> bool { self.iter().any(|x| &x.validator_public_key() == public_key) } @@ -318,6 +344,14 @@ impl BidsExt for Vec { && x.era_id() == bid_kind.era_id() }) .map(|(idx, _)| idx), + BidKind::Reservation(_) => self + .iter() + .find_position(|x| { + x.is_reservation() + && x.validator_public_key() == bid_kind.validator_public_key() + && x.delegator_public_key() == bid_kind.delegator_public_key() + }) + .map(|(idx, _)| idx), }; match maybe_index { diff --git a/types/src/system/auction/bid_addr.rs b/types/src/system/auction/bid_addr.rs index 65eca7c819..2f01e00322 100644 --- a/types/src/system/auction/bid_addr.rs +++ b/types/src/system/auction/bid_addr.rs @@ -176,6 +176,14 @@ impl BidAddr { } } + /// Create a new instance of a [`BidAddr`]. + pub fn new_reservation(validator: &PublicKey, delegator: &PublicKey) -> Self { + BidAddr::Reservation { + validator: validator.into(), + delegator: delegator.into(), + } + } + /// Returns the common prefix of all delegators to the cited validator. pub fn delegators_prefix(&self) -> Result, Error> { let validator = self.validator_account_hash(); diff --git a/types/src/system/auction/bid_kind.rs b/types/src/system/auction/bid_kind.rs index 094acce004..9e227ccd9c 100644 --- a/types/src/system/auction/bid_kind.rs +++ b/types/src/system/auction/bid_kind.rs @@ -15,6 +15,8 @@ use datasize::DataSize; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; +use super::Reservation; + /// BidKindTag variants. #[allow(clippy::large_enum_variant)] #[repr(u8)] @@ -30,6 +32,8 @@ pub enum BidKindTag { Bridge = 3, /// Validator credit bid. Credit = 4, + /// Reservation bid. + Reservation = 5, } /// Auction bid variants. @@ -49,6 +53,8 @@ pub enum BidKind { Bridge(Box), /// Credited amount. Credit(Box), + /// Reservation + Reservation(Box), } impl BidKind { @@ -60,6 +66,7 @@ impl BidKind { BidKind::Delegator(delegator_bid) => delegator_bid.validator_public_key().clone(), BidKind::Bridge(bridge) => bridge.old_validator_public_key().clone(), BidKind::Credit(validator_credit) => validator_credit.validator_public_key().clone(), + BidKind::Reservation(reservation) => reservation.validator_public_key().clone(), } } @@ -70,7 +77,8 @@ impl BidKind { BidKind::Unified(_) | BidKind::Validator(_) | BidKind::Delegator(_) - | BidKind::Credit(_) => None, + | BidKind::Credit(_) + | BidKind::Reservation(_) => None, } } @@ -97,6 +105,14 @@ impl BidKind { let era_id = credit.era_id(); BidAddr::Credit { validator, era_id } } + BidKind::Reservation(reservation_bid) => { + let validator = reservation_bid.validator_public_key().to_account_hash(); + let delegator = reservation_bid.delegator_public_key().to_account_hash(); + BidAddr::Reservation { + validator, + delegator, + } + } } } @@ -125,13 +141,18 @@ impl BidKind { matches!(self, BidKind::Credit(_)) } + /// Is this instance a reservation? + pub fn is_reservation(&self) -> bool { + matches!(self, BidKind::Reservation(_)) + } + /// The staked amount. pub fn staked_amount(&self) -> Option { match self { BidKind::Unified(bid) => Some(*bid.staked_amount()), BidKind::Validator(validator_bid) => Some(validator_bid.staked_amount()), BidKind::Delegator(delegator) => Some(delegator.staked_amount()), - BidKind::Bridge(_) => None, + BidKind::Bridge(_) | BidKind::Reservation(_) => None, BidKind::Credit(credit) => Some(credit.amount()), } } @@ -142,7 +163,7 @@ impl BidKind { BidKind::Unified(bid) => Some(*bid.bonding_purse()), BidKind::Validator(validator_bid) => Some(*validator_bid.bonding_purse()), BidKind::Delegator(delegator) => Some(*delegator.bonding_purse()), - BidKind::Bridge(_) | BidKind::Credit(_) => None, + BidKind::Bridge(_) | BidKind::Credit(_) | BidKind::Reservation(_) => None, } } @@ -153,7 +174,8 @@ impl BidKind { | BidKind::Validator(_) | BidKind::Bridge(_) | BidKind::Credit(_) => None, - BidKind::Delegator(delegator) => Some(delegator.delegator_public_key().clone()), + BidKind::Delegator(bid) => Some(bid.delegator_public_key().clone()), + BidKind::Reservation(bid) => Some(bid.delegator_public_key().clone()), } } @@ -163,7 +185,7 @@ impl BidKind { BidKind::Unified(bid) => bid.inactive(), BidKind::Validator(validator_bid) => validator_bid.inactive(), BidKind::Delegator(delegator) => delegator.staked_amount().is_zero(), - BidKind::Bridge(_) => false, + BidKind::Bridge(_) | BidKind::Reservation(_) => false, BidKind::Credit(credit) => credit.amount().is_zero(), } } @@ -177,7 +199,7 @@ impl BidKind { BidKind::Unified(bid) => bid.is_locked(timestamp_millis), BidKind::Validator(validator_bid) => validator_bid.is_locked(timestamp_millis), BidKind::Delegator(delegator) => delegator.is_locked(timestamp_millis), - BidKind::Bridge(_) | BidKind::Credit(_) => false, + BidKind::Bridge(_) | BidKind::Credit(_) | BidKind::Reservation(_) => false, } } @@ -197,7 +219,7 @@ impl BidKind { .is_locked_with_vesting_schedule(timestamp_millis, vesting_schedule_period_millis), BidKind::Delegator(delegator) => delegator .is_locked_with_vesting_schedule(timestamp_millis, vesting_schedule_period_millis), - BidKind::Bridge(_) | BidKind::Credit(_) => false, + BidKind::Bridge(_) | BidKind::Credit(_) | BidKind::Reservation(_) => false, } } @@ -208,7 +230,7 @@ impl BidKind { BidKind::Unified(bid) => bid.vesting_schedule(), BidKind::Validator(validator_bid) => validator_bid.vesting_schedule(), BidKind::Delegator(delegator) => delegator.vesting_schedule(), - BidKind::Bridge(_) | BidKind::Credit(_) => None, + BidKind::Bridge(_) | BidKind::Credit(_) | BidKind::Reservation(_) => None, } } @@ -220,6 +242,7 @@ impl BidKind { BidKind::Delegator(_) => BidKindTag::Delegator, BidKind::Bridge(_) => BidKindTag::Bridge, BidKind::Credit(_) => BidKindTag::Credit, + BidKind::Reservation(_) => BidKindTag::Reservation, } } @@ -228,7 +251,10 @@ impl BidKind { match self { BidKind::Bridge(bridge) => Some(*bridge.era_id()), BidKind::Credit(credit) => Some(credit.era_id()), - BidKind::Unified(_) | BidKind::Validator(_) | BidKind::Delegator(_) => None, + BidKind::Unified(_) + | BidKind::Validator(_) + | BidKind::Delegator(_) + | BidKind::Reservation(_) => None, } } } @@ -242,6 +268,7 @@ impl ToBytes for BidKind { BidKind::Delegator(delegator_bid) => (BidKindTag::Delegator, delegator_bid.to_bytes()?), BidKind::Bridge(bridge) => (BidKindTag::Bridge, bridge.to_bytes()?), BidKind::Credit(credit) => (BidKindTag::Credit, credit.to_bytes()?), + BidKind::Reservation(reservation) => (BidKindTag::Reservation, reservation.to_bytes()?), }; result.push(tag as u8); result.append(&mut serialized_data); @@ -256,6 +283,7 @@ impl ToBytes for BidKind { BidKind::Delegator(delegator_bid) => delegator_bid.serialized_length(), BidKind::Bridge(bridge) => bridge.serialized_length(), BidKind::Credit(credit) => credit.serialized_length(), + BidKind::Reservation(reservation) => reservation.serialized_length(), } } @@ -267,6 +295,7 @@ impl ToBytes for BidKind { BidKind::Delegator(delegator_bid) => delegator_bid.write_bytes(writer)?, BidKind::Bridge(bridge) => bridge.write_bytes(writer)?, BidKind::Credit(credit) => credit.write_bytes(writer)?, + BidKind::Reservation(reservation) => reservation.write_bytes(writer)?, }; Ok(()) } diff --git a/types/src/system/auction/reservation.rs b/types/src/system/auction/reservation.rs new file mode 100644 index 0000000000..7b4a28d908 --- /dev/null +++ b/types/src/system/auction/reservation.rs @@ -0,0 +1,127 @@ +use alloc::vec::Vec; +use core::fmt::{self, Display, Formatter}; + +#[cfg(feature = "datasize")] +use datasize::DataSize; +#[cfg(feature = "json-schema")] +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; + +use crate::{ + bytesrepr::{self, FromBytes, ToBytes}, + CLType, CLTyped, PublicKey, +}; + +/// Represents a validator reserving a slot for specific delegator +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[cfg_attr(feature = "datasize", derive(DataSize))] +#[cfg_attr(feature = "json-schema", derive(JsonSchema))] +#[serde(deny_unknown_fields)] +pub struct Reservation { + /// Delegator public key + delegator_public_key: PublicKey, + /// Validator public key + validator_public_key: PublicKey, +} + +impl Reservation { + /// Creates a new [`Reservation`] + pub fn new(validator_public_key: PublicKey, delegator_public_key: PublicKey) -> Self { + Self { + delegator_public_key, + validator_public_key, + } + } + + /// Returns public key of the delegator. + pub fn delegator_public_key(&self) -> &PublicKey { + &self.delegator_public_key + } + + /// Returns delegatee + pub fn validator_public_key(&self) -> &PublicKey { + &self.validator_public_key + } +} + +impl CLTyped for Reservation { + fn cl_type() -> CLType { + CLType::Any + } +} + +impl ToBytes for Reservation { + fn to_bytes(&self) -> Result, bytesrepr::Error> { + let mut buffer = bytesrepr::allocate_buffer(self)?; + buffer.extend(self.delegator_public_key.to_bytes()?); + buffer.extend(self.validator_public_key.to_bytes()?); + Ok(buffer) + } + + fn serialized_length(&self) -> usize { + self.delegator_public_key.serialized_length() + + self.validator_public_key.serialized_length() + } + + fn write_bytes(&self, writer: &mut Vec) -> Result<(), bytesrepr::Error> { + self.delegator_public_key.write_bytes(writer)?; + self.validator_public_key.write_bytes(writer)?; + Ok(()) + } +} + +impl FromBytes for Reservation { + fn from_bytes(bytes: &[u8]) -> Result<(Self, &[u8]), bytesrepr::Error> { + let (delegator_public_key, bytes) = PublicKey::from_bytes(bytes)?; + let (validator_public_key, bytes) = PublicKey::from_bytes(bytes)?; + Ok(( + Self { + delegator_public_key, + validator_public_key, + }, + bytes, + )) + } +} + +impl Display for Reservation { + fn fmt(&self, formatter: &mut Formatter) -> fmt::Result { + write!( + formatter, + "Reservation {{ delegator {}, validator {} }}", + self.delegator_public_key, self.validator_public_key + ) + } +} + +#[cfg(test)] +mod tests { + use crate::{bytesrepr, system::auction::Reservation, PublicKey, SecretKey}; + + #[test] + fn serialization_roundtrip() { + let delegator_public_key: PublicKey = PublicKey::from( + &SecretKey::ed25519_from_bytes([42; SecretKey::ED25519_LENGTH]).unwrap(), + ); + + let validator_public_key: PublicKey = PublicKey::from( + &SecretKey::ed25519_from_bytes([43; SecretKey::ED25519_LENGTH]).unwrap(), + ); + let entry = Reservation::new(delegator_public_key, validator_public_key); + bytesrepr::test_serialization_roundtrip(&entry); + } +} + +#[cfg(test)] +mod prop_tests { + use proptest::prelude::*; + + use crate::{bytesrepr, gens}; + + proptest! { + #[test] + fn test_value_bid(bid in gens::reservation_arb()) { + bytesrepr::test_serialization_roundtrip(&bid); + } + } +} diff --git a/utils/global-state-update-gen/src/generic.rs b/utils/global-state-update-gen/src/generic.rs index 56d344c90e..9bdf444442 100644 --- a/utils/global-state-update-gen/src/generic.rs +++ b/utils/global-state-update-gen/src/generic.rs @@ -17,8 +17,8 @@ use casper_engine_test_support::LmdbWasmTestBuilder; use casper_execution_engine::engine_state::engine_config::DEFAULT_PROTOCOL_VERSION; use casper_types::{ system::auction::{ - Bid, BidKind, BidsExt, Delegator, SeigniorageRecipient, SeigniorageRecipientsSnapshot, - ValidatorBid, ValidatorCredit, + Bid, BidKind, BidsExt, Delegator, Reservation, SeigniorageRecipient, + SeigniorageRecipientsSnapshot, ValidatorBid, ValidatorCredit, }, CLValue, EraId, PublicKey, StoredValue, U512, }; @@ -331,6 +331,12 @@ pub fn add_and_remove_bids( public_key.clone(), credit.era_id(), ))), + BidKind::Reservation(reservation_bid) => { + BidKind::Reservation(Box::new(Reservation::new( + public_key.clone(), + reservation_bid.delegator_public_key().clone(), + ))) + } }; state.set_bid(reset_bid, slash_instead_of_unbonding); } diff --git a/utils/global-state-update-gen/src/generic/state_tracker.rs b/utils/global-state-update-gen/src/generic/state_tracker.rs index 4b6a0c2110..18000a48b8 100644 --- a/utils/global-state-update-gen/src/generic/state_tracker.rs +++ b/utils/global-state-update-gen/src/generic/state_tracker.rs @@ -79,6 +79,10 @@ impl StateTracker { BidKind::Credit(credit) => { BidAddr::new_credit(credit.validator_public_key(), credit.era_id()) } + BidKind::Reservation(reservation) => BidAddr::new_reservation( + reservation.validator_public_key(), + reservation.delegator_public_key(), + ), }; let _ = self @@ -320,6 +324,12 @@ impl StateTracker { BidKind::Credit(credit) => existing_bids .credit(credit.validator_public_key()) .map(|existing_credit| BidKind::Credit(Box::new(existing_credit))), + BidKind::Reservation(reservation) => existing_bids + .reservation_by_public_keys( + reservation.validator_public_key(), + reservation.delegator_public_key(), + ) + .map(|exisiting_reservation| BidKind::Reservation(Box::new(exisiting_reservation))), } } From 3ed40248ed127a7301e05845788c9ffcf52d7d16 Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Tue, 16 Jul 2024 11:41:05 +0200 Subject: [PATCH 26/38] Fix reservation generators --- types/src/gens.rs | 7 ++++++- types/src/system/auction.rs | 16 +++++++++++++++- types/src/system/auction/bid_kind.rs | 14 ++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/types/src/gens.rs b/types/src/gens.rs index 74673d9ad9..e62a925de1 100644 --- a/types/src/gens.rs +++ b/types/src/gens.rs @@ -634,9 +634,13 @@ fn delegation_rate_arb() -> impl Strategy { 0..=DELEGATION_RATE_DENOMINATOR // Maximum, allowed value for delegation rate. } +pub(crate) fn reservation_bid_arb() -> impl Strategy { + reservation_arb().prop_map(|reservation| BidKind::Reservation(Box::new(reservation))) +} + pub(crate) fn reservation_arb() -> impl Strategy { (public_key_arb_no_system(), public_key_arb_no_system()) - .prop_map(|(delegator_pk, validator_pk)| Reservation::new(delegator_pk, validator_pk)) + .prop_map(|(validator_pk, delegator_pk)| Reservation::new(validator_pk, delegator_pk)) } pub(crate) fn unified_bid_arb( @@ -823,6 +827,7 @@ pub fn stored_value_arb() -> impl Strategy { validator_bid_arb().prop_map(StoredValue::BidKind), delegator_bid_arb().prop_map(StoredValue::BidKind), credit_bid_arb().prop_map(StoredValue::BidKind), + reservation_bid_arb().prop_map(StoredValue::BidKind), withdraws_arb(1..50).prop_map(StoredValue::Withdraw), unbondings_arb(1..50).prop_map(StoredValue::Unbonding), message_topic_summary_arb().prop_map(StoredValue::MessageTopic), diff --git a/types/src/system/auction.rs b/types/src/system/auction.rs index 320d48a50a..fafd876ced 100644 --- a/types/src/system/auction.rs +++ b/types/src/system/auction.rs @@ -366,7 +366,7 @@ impl BidsExt for Vec { } #[cfg(test)] -mod prop_tests { +mod prop_test_delegator { use proptest::prelude::*; use crate::{bytesrepr, gens}; @@ -378,3 +378,17 @@ mod prop_tests { } } } + +#[cfg(test)] +mod prop_test_reservation { + use proptest::prelude::*; + + use crate::{bytesrepr, gens}; + + proptest! { + #[test] + fn test_value_bid(bid in gens::reservation_arb()) { + bytesrepr::test_serialization_roundtrip(&bid); + } + } +} diff --git a/types/src/system/auction/bid_kind.rs b/types/src/system/auction/bid_kind.rs index 9e227ccd9c..837635e956 100644 --- a/types/src/system/auction/bid_kind.rs +++ b/types/src/system/auction/bid_kind.rs @@ -423,3 +423,17 @@ mod prop_test_bid_kind_validator_credit { } } } + +#[cfg(test)] +mod prop_test_bid_kind_reservation { + use proptest::prelude::*; + + use crate::{bytesrepr, gens}; + + proptest! { + #[test] + fn test_value_bid_kind_reservation(bid_kind in gens::reservation_bid_arb()) { + bytesrepr::test_serialization_roundtrip(&bid_kind); + } + } +} From e09ebb469d57bf27ffda3d338c501753b2513c3e Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Tue, 16 Jul 2024 13:13:18 +0200 Subject: [PATCH 27/38] Add Reservation, BidKind::Reservation to data schema --- resources/test/sse_data_schema.json | 40 +++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/resources/test/sse_data_schema.json b/resources/test/sse_data_schema.json index c4d5f34b8d..b0a3381461 100644 --- a/resources/test/sse_data_schema.json +++ b/resources/test/sse_data_schema.json @@ -3248,6 +3248,19 @@ } }, "additionalProperties": false + }, + { + "description": "Reservation", + "type": "object", + "required": [ + "Reservation" + ], + "properties": { + "Reservation": { + "$ref": "#/definitions/Reservation" + } + }, + "additionalProperties": false } ] }, @@ -3403,6 +3416,33 @@ }, "additionalProperties": false }, + "Reservation": { + "description": "Represents a validator reserving a slot for specific delegator", + "type": "object", + "required": [ + "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" + } + ] + } + }, + "additionalProperties": false + }, "ExecutionResultV2": { "description": "The result of executing a single transaction.", "type": "object", From f63c008713e461e64ab9ee6dde1cdfbf87624806 Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Tue, 16 Jul 2024 14:36:54 +0200 Subject: [PATCH 28/38] Fix reservation serialization tests --- types/src/gens.rs | 1 - types/src/system/auction/bid_kind.rs | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/types/src/gens.rs b/types/src/gens.rs index e62a925de1..b6736d5ea3 100644 --- a/types/src/gens.rs +++ b/types/src/gens.rs @@ -827,7 +827,6 @@ pub fn stored_value_arb() -> impl Strategy { validator_bid_arb().prop_map(StoredValue::BidKind), delegator_bid_arb().prop_map(StoredValue::BidKind), credit_bid_arb().prop_map(StoredValue::BidKind), - reservation_bid_arb().prop_map(StoredValue::BidKind), withdraws_arb(1..50).prop_map(StoredValue::Withdraw), unbondings_arb(1..50).prop_map(StoredValue::Unbonding), message_topic_summary_arb().prop_map(StoredValue::MessageTopic), diff --git a/types/src/system/auction/bid_kind.rs b/types/src/system/auction/bid_kind.rs index 837635e956..69ee4c2c76 100644 --- a/types/src/system/auction/bid_kind.rs +++ b/types/src/system/auction/bid_kind.rs @@ -321,6 +321,8 @@ impl FromBytes for BidKind { .map(|(bridge, remainder)| (BidKind::Bridge(Box::new(bridge)), remainder)), tag if tag == BidKindTag::Credit as u8 => ValidatorCredit::from_bytes(remainder) .map(|(credit, remainder)| (BidKind::Credit(Box::new(credit)), remainder)), + tag if tag == BidKindTag::Reservation as u8 => Reservation::from_bytes(remainder) + .map(|(reservation, remainder)| (BidKind::Reservation(Box::new(reservation)), remainder)), _ => Err(bytesrepr::Error::Formatting), } } From 89d8fe2f676e42ce64e23da435f2ec702f2dbb1e Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Wed, 17 Jul 2024 10:06:38 +0200 Subject: [PATCH 29/38] Format --- types/src/gens.rs | 1 + types/src/system/auction/bid_kind.rs | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/types/src/gens.rs b/types/src/gens.rs index b6736d5ea3..687fea59bb 100644 --- a/types/src/gens.rs +++ b/types/src/gens.rs @@ -826,6 +826,7 @@ pub fn stored_value_arb() -> impl Strategy { unified_bid_arb(0..3).prop_map(StoredValue::BidKind), validator_bid_arb().prop_map(StoredValue::BidKind), delegator_bid_arb().prop_map(StoredValue::BidKind), + reservation_bid_arb().prop_map(StoredValue::BidKind), credit_bid_arb().prop_map(StoredValue::BidKind), withdraws_arb(1..50).prop_map(StoredValue::Withdraw), unbondings_arb(1..50).prop_map(StoredValue::Unbonding), diff --git a/types/src/system/auction/bid_kind.rs b/types/src/system/auction/bid_kind.rs index 69ee4c2c76..46e5e372e6 100644 --- a/types/src/system/auction/bid_kind.rs +++ b/types/src/system/auction/bid_kind.rs @@ -321,8 +321,11 @@ impl FromBytes for BidKind { .map(|(bridge, remainder)| (BidKind::Bridge(Box::new(bridge)), remainder)), tag if tag == BidKindTag::Credit as u8 => ValidatorCredit::from_bytes(remainder) .map(|(credit, remainder)| (BidKind::Credit(Box::new(credit)), remainder)), - tag if tag == BidKindTag::Reservation as u8 => Reservation::from_bytes(remainder) - .map(|(reservation, remainder)| (BidKind::Reservation(Box::new(reservation)), remainder)), + tag if tag == BidKindTag::Reservation as u8 => { + Reservation::from_bytes(remainder).map(|(reservation, remainder)| { + (BidKind::Reservation(Box::new(reservation)), remainder) + }) + } _ => Err(bytesrepr::Error::Formatting), } } From 769f7cff52dcd3761ffc7b74d1d46aef86894a65 Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Fri, 26 Jul 2024 09:42:33 +0200 Subject: [PATCH 30/38] Add reservation entrypoints, removed panicking method handlers --- execution_engine/src/runtime/mod.rs | 2 -- types/src/system/auction/entry_points.rs | 32 ++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/execution_engine/src/runtime/mod.rs b/execution_engine/src/runtime/mod.rs index f24d39f653..361efd4990 100644 --- a/execution_engine/src/runtime/mod.rs +++ b/execution_engine/src/runtime/mod.rs @@ -1123,8 +1123,6 @@ where CLValue::from_t(()).map_err(Self::reverter) })(), - auction::METHOD_ADD_RESERVATIONS => todo!(), - auction::METHOD_CANCEL_RESERVATIONS => todo!(), _ => CLValue::from_t(()).map_err(Self::reverter), }; diff --git a/types/src/system/auction/entry_points.rs b/types/src/system/auction/entry_points.rs index cc9d17fbe5..46f4db8d8c 100644 --- a/types/src/system/auction/entry_points.rs +++ b/types/src/system/auction/entry_points.rs @@ -9,10 +9,12 @@ use crate::{ CLType, CLTyped, EntryPoint, EntryPointAccess, EntryPointPayment, EntryPointType, EntryPoints, Parameter, PublicKey, U512, }; +use alloc::boxed::Box; use super::{ - ARG_MAXIMUM_DELEGATION_AMOUNT, ARG_MINIMUM_DELEGATION_AMOUNT, ARG_NEW_PUBLIC_KEY, - ARG_REWARDS_MAP, METHOD_CHANGE_BID_PUBLIC_KEY, + ARG_DELEGATORS, ARG_MAXIMUM_DELEGATION_AMOUNT, ARG_MINIMUM_DELEGATION_AMOUNT, + ARG_NEW_PUBLIC_KEY, ARG_REWARDS_MAP, METHOD_ADD_RESERVATIONS, METHOD_CANCEL_RESERVATIONS, + METHOD_CHANGE_BID_PUBLIC_KEY, }; /// Creates auction contract entry points. @@ -167,5 +169,31 @@ pub fn auction_entry_points() -> EntryPoints { ); entry_points.add_entry_point(entry_point); + let entry_point = EntryPoint::new( + METHOD_ADD_RESERVATIONS, + vec![ + Parameter::new(ARG_VALIDATOR, PublicKey::cl_type()), + Parameter::new(ARG_DELEGATORS, CLType::List(Box::new(PublicKey::cl_type()))), + ], + CLType::Unit, + EntryPointAccess::Public, + EntryPointType::Called, + EntryPointPayment::Caller, + ); + entry_points.add_entry_point(entry_point); + + let entry_point = EntryPoint::new( + METHOD_CANCEL_RESERVATIONS, + vec![ + Parameter::new(ARG_VALIDATOR, PublicKey::cl_type()), + Parameter::new(ARG_DELEGATORS, CLType::List(Box::new(PublicKey::cl_type()))), + ], + CLType::Unit, + EntryPointAccess::Public, + EntryPointType::Called, + EntryPointPayment::Caller, + ); + entry_points.add_entry_point(entry_point); + entry_points } From 601e01a87450c9c6398f8f1dd2798bf231815a96 Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Fri, 26 Jul 2024 12:58:48 +0200 Subject: [PATCH 31/38] Add Reservation::delegation_rate field --- types/src/gens.rs | 10 +++++++-- types/src/system/auction/reservation.rs | 23 ++++++++++++++++++-- utils/global-state-update-gen/src/generic.rs | 1 + 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/types/src/gens.rs b/types/src/gens.rs index 687fea59bb..e763a99d36 100644 --- a/types/src/gens.rs +++ b/types/src/gens.rs @@ -639,8 +639,14 @@ pub(crate) fn reservation_bid_arb() -> impl Strategy { } pub(crate) fn reservation_arb() -> impl Strategy { - (public_key_arb_no_system(), public_key_arb_no_system()) - .prop_map(|(validator_pk, delegator_pk)| Reservation::new(validator_pk, delegator_pk)) + ( + public_key_arb_no_system(), + public_key_arb_no_system(), + delegation_rate_arb(), + ) + .prop_map(|(validator_pk, delegator_pk, delegation_rate)| { + Reservation::new(validator_pk, delegator_pk, delegation_rate) + }) } pub(crate) fn unified_bid_arb( diff --git a/types/src/system/auction/reservation.rs b/types/src/system/auction/reservation.rs index 7b4a28d908..701c719665 100644 --- a/types/src/system/auction/reservation.rs +++ b/types/src/system/auction/reservation.rs @@ -12,6 +12,8 @@ use crate::{ CLType, CLTyped, PublicKey, }; +use super::DelegationRate; + /// Represents a validator reserving a slot for specific delegator #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[cfg_attr(feature = "datasize", derive(DataSize))] @@ -22,14 +24,21 @@ pub struct Reservation { delegator_public_key: PublicKey, /// Validator public key validator_public_key: PublicKey, + /// Individual delegation rate + delegation_rate: DelegationRate, } impl Reservation { /// Creates a new [`Reservation`] - pub fn new(validator_public_key: PublicKey, delegator_public_key: PublicKey) -> Self { + pub fn new( + validator_public_key: PublicKey, + delegator_public_key: PublicKey, + delegation_rate: DelegationRate, + ) -> Self { Self { delegator_public_key, validator_public_key, + delegation_rate, } } @@ -42,6 +51,11 @@ impl Reservation { pub fn validator_public_key(&self) -> &PublicKey { &self.validator_public_key } + + /// Gets the delegation rate of the provided bid + pub fn delegation_rate(&self) -> &DelegationRate { + &self.delegation_rate + } } impl CLTyped for Reservation { @@ -55,17 +69,20 @@ impl ToBytes for Reservation { let mut buffer = bytesrepr::allocate_buffer(self)?; buffer.extend(self.delegator_public_key.to_bytes()?); buffer.extend(self.validator_public_key.to_bytes()?); + buffer.extend(self.delegation_rate.to_bytes()?); Ok(buffer) } fn serialized_length(&self) -> usize { self.delegator_public_key.serialized_length() + self.validator_public_key.serialized_length() + + self.delegation_rate.serialized_length() } fn write_bytes(&self, writer: &mut Vec) -> Result<(), bytesrepr::Error> { self.delegator_public_key.write_bytes(writer)?; self.validator_public_key.write_bytes(writer)?; + self.delegation_rate.write_bytes(writer)?; Ok(()) } } @@ -74,10 +91,12 @@ impl FromBytes for Reservation { fn from_bytes(bytes: &[u8]) -> Result<(Self, &[u8]), bytesrepr::Error> { let (delegator_public_key, bytes) = PublicKey::from_bytes(bytes)?; let (validator_public_key, bytes) = PublicKey::from_bytes(bytes)?; + let (delegation_rate, bytes) = FromBytes::from_bytes(bytes)?; Ok(( Self { delegator_public_key, validator_public_key, + delegation_rate, }, bytes, )) @@ -107,7 +126,7 @@ mod tests { let validator_public_key: PublicKey = PublicKey::from( &SecretKey::ed25519_from_bytes([43; SecretKey::ED25519_LENGTH]).unwrap(), ); - let entry = Reservation::new(delegator_public_key, validator_public_key); + let entry = Reservation::new(delegator_public_key, validator_public_key, 0); bytesrepr::test_serialization_roundtrip(&entry); } } diff --git a/utils/global-state-update-gen/src/generic.rs b/utils/global-state-update-gen/src/generic.rs index 9bdf444442..2ac3363966 100644 --- a/utils/global-state-update-gen/src/generic.rs +++ b/utils/global-state-update-gen/src/generic.rs @@ -335,6 +335,7 @@ pub fn add_and_remove_bids( BidKind::Reservation(Box::new(Reservation::new( public_key.clone(), reservation_bid.delegator_public_key().clone(), + *reservation_bid.delegation_rate(), ))) } }; From 2f9a78ae6355caf32e52aa1c799feefd01f757ad Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Fri, 26 Jul 2024 13:46:22 +0200 Subject: [PATCH 32/38] Fix schema --- resources/test/sse_data_schema.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/resources/test/sse_data_schema.json b/resources/test/sse_data_schema.json index b0a3381461..f6df29a6f3 100644 --- a/resources/test/sse_data_schema.json +++ b/resources/test/sse_data_schema.json @@ -3420,6 +3420,7 @@ "description": "Represents a validator reserving a slot for specific delegator", "type": "object", "required": [ + "delegation_rate", "delegator_public_key", "validator_public_key" ], @@ -3439,6 +3440,12 @@ "$ref": "#/definitions/PublicKey" } ] + }, + "delegation_rate": { + "description": "Individual delegation rate", + "type": "integer", + "format": "uint8", + "minimum": 0.0 } }, "additionalProperties": false From 45f66d0350fc04e3f1609b35c882173dacd7589f Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Fri, 26 Jul 2024 13:51:07 +0200 Subject: [PATCH 33/38] Include delegation rate in reservation contracts --- .../contracts/client/add-reservations/src/main.rs | 6 +++--- .../contracts/client/cancel-reservations/src/main.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/smart_contracts/contracts/client/add-reservations/src/main.rs b/smart_contracts/contracts/client/add-reservations/src/main.rs index ec68088763..3fa2297d94 100644 --- a/smart_contracts/contracts/client/add-reservations/src/main.rs +++ b/smart_contracts/contracts/client/add-reservations/src/main.rs @@ -6,9 +6,9 @@ extern crate alloc; use alloc::vec::Vec; use casper_contract::contract_api::runtime; -use casper_types::{system::auction, PublicKey}; +use casper_types::{system::auction::{self, DelegationRate}, PublicKey}; -fn add_reservations(_validator: PublicKey, _delegators: &[PublicKey]) { +fn add_reservations(_validator: PublicKey, _delegators: Vec<(PublicKey, DelegationRate)>) { todo!(); } @@ -21,5 +21,5 @@ pub extern "C" fn call() { let delegators: Vec = runtime::get_named_arg(auction::ARG_DELEGATORS); let validator = runtime::get_named_arg(auction::ARG_VALIDATOR); - add_reservations(validator, &delegators); + add_reservations(validator, delegators); } diff --git a/smart_contracts/contracts/client/cancel-reservations/src/main.rs b/smart_contracts/contracts/client/cancel-reservations/src/main.rs index eddd320c6e..4416cdbaf2 100644 --- a/smart_contracts/contracts/client/cancel-reservations/src/main.rs +++ b/smart_contracts/contracts/client/cancel-reservations/src/main.rs @@ -6,9 +6,9 @@ extern crate alloc; use alloc::vec::Vec; use casper_contract::contract_api::runtime; -use casper_types::{system::auction, PublicKey}; +use casper_types::{system::auction::{self, DelegationRate}, PublicKey}; -fn cancel_reservations(_validator: PublicKey, _delegators: &[PublicKey]) { +fn cancel_reservations(_validator: PublicKey, _delegators: Vec<(PublicKey, DelegationRate)>) { todo!(); } @@ -21,5 +21,5 @@ pub extern "C" fn call() { let delegators: Vec = runtime::get_named_arg(auction::ARG_DELEGATORS); let validator = runtime::get_named_arg(auction::ARG_VALIDATOR); - cancel_reservations(validator, &delegators); + cancel_reservations(validator, delegators); } From 3383beb05a65df88c84a20fcca5c0c4405495c6e Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Fri, 26 Jul 2024 16:27:58 +0200 Subject: [PATCH 34/38] Take reservation objects as input to reservation contracts --- .../contracts/client/add-reservations/src/main.rs | 14 ++++++++------ .../client/cancel-reservations/src/main.rs | 7 +++++-- types/src/system/auction/constants.rs | 4 ++-- types/src/system/auction/entry_points.rs | 10 +++++----- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/smart_contracts/contracts/client/add-reservations/src/main.rs b/smart_contracts/contracts/client/add-reservations/src/main.rs index 3fa2297d94..f586a26f67 100644 --- a/smart_contracts/contracts/client/add-reservations/src/main.rs +++ b/smart_contracts/contracts/client/add-reservations/src/main.rs @@ -6,20 +6,22 @@ extern crate alloc; use alloc::vec::Vec; use casper_contract::contract_api::runtime; -use casper_types::{system::auction::{self, DelegationRate}, PublicKey}; +use casper_types::{ + system::auction::{self, DelegationRate, Reservation}, + PublicKey, +}; -fn add_reservations(_validator: PublicKey, _delegators: Vec<(PublicKey, DelegationRate)>) { +fn add_reservations(reservations: Vec) { todo!(); } // Add delegators to validator's reserved list. // -// Accepts delegators' and validator's public keys. +// Accepts reservations. // Issues an add_reservations request to the auction contract. #[no_mangle] pub extern "C" fn call() { - let delegators: Vec = runtime::get_named_arg(auction::ARG_DELEGATORS); - let validator = runtime::get_named_arg(auction::ARG_VALIDATOR); + let reservations: Vec = runtime::get_named_arg(auction::ARG_RESERVATIONS); - add_reservations(validator, delegators); + add_reservations(reservations); } diff --git a/smart_contracts/contracts/client/cancel-reservations/src/main.rs b/smart_contracts/contracts/client/cancel-reservations/src/main.rs index 4416cdbaf2..72d22edb49 100644 --- a/smart_contracts/contracts/client/cancel-reservations/src/main.rs +++ b/smart_contracts/contracts/client/cancel-reservations/src/main.rs @@ -6,9 +6,12 @@ extern crate alloc; use alloc::vec::Vec; use casper_contract::contract_api::runtime; -use casper_types::{system::auction::{self, DelegationRate}, PublicKey}; +use casper_types::{ + system::auction::{self, DelegationRate}, + PublicKey, +}; -fn cancel_reservations(_validator: PublicKey, _delegators: Vec<(PublicKey, DelegationRate)>) { +fn cancel_reservations(_validator: PublicKey, _delegators: Vec) { todo!(); } diff --git a/types/src/system/auction/constants.rs b/types/src/system/auction/constants.rs index 27edc0a506..4fb713da65 100644 --- a/types/src/system/auction/constants.rs +++ b/types/src/system/auction/constants.rs @@ -28,8 +28,8 @@ pub const ARG_NEW_PUBLIC_KEY: &str = "new_public_key"; pub const ARG_VALIDATOR: &str = "validator"; /// Named constant for `delegator`. pub const ARG_DELEGATOR: &str = "delegator"; -/// Named constant for `delegators`. -pub const ARG_DELEGATORS: &str = "delegators"; +/// Named constant for `reservations`. +pub const ARG_RESERVATIONS: &str = "reservations"; /// Named constant for `validator_purse`. pub const ARG_VALIDATOR_PURSE: &str = "validator_purse"; /// Named constant for `validator_keys`. diff --git a/types/src/system/auction/entry_points.rs b/types/src/system/auction/entry_points.rs index 46f4db8d8c..b7aba34c00 100644 --- a/types/src/system/auction/entry_points.rs +++ b/types/src/system/auction/entry_points.rs @@ -12,7 +12,7 @@ use crate::{ use alloc::boxed::Box; use super::{ - ARG_DELEGATORS, ARG_MAXIMUM_DELEGATION_AMOUNT, ARG_MINIMUM_DELEGATION_AMOUNT, + Reservation, ARG_DELEGATORS, ARG_MAXIMUM_DELEGATION_AMOUNT, ARG_MINIMUM_DELEGATION_AMOUNT, ARG_NEW_PUBLIC_KEY, ARG_REWARDS_MAP, METHOD_ADD_RESERVATIONS, METHOD_CANCEL_RESERVATIONS, METHOD_CHANGE_BID_PUBLIC_KEY, }; @@ -171,10 +171,10 @@ pub fn auction_entry_points() -> EntryPoints { let entry_point = EntryPoint::new( METHOD_ADD_RESERVATIONS, - vec![ - Parameter::new(ARG_VALIDATOR, PublicKey::cl_type()), - Parameter::new(ARG_DELEGATORS, CLType::List(Box::new(PublicKey::cl_type()))), - ], + vec![Parameter::new( + ARG_DELEGATORS, + CLType::List(Box::new(Reservation::cl_type())), + )], CLType::Unit, EntryPointAccess::Public, EntryPointType::Called, From 5e08e920e25cd70ecfa457f5a48f3ed4354cd6aa Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Sun, 28 Jul 2024 08:45:33 +0200 Subject: [PATCH 35/38] Fix reservation constants --- types/src/system/auction/constants.rs | 2 ++ types/src/system/auction/entry_points.rs | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/types/src/system/auction/constants.rs b/types/src/system/auction/constants.rs index 4fb713da65..fc99c639b8 100644 --- a/types/src/system/auction/constants.rs +++ b/types/src/system/auction/constants.rs @@ -28,6 +28,8 @@ pub const ARG_NEW_PUBLIC_KEY: &str = "new_public_key"; pub const ARG_VALIDATOR: &str = "validator"; /// Named constant for `delegator`. pub const ARG_DELEGATOR: &str = "delegator"; +/// Named constant for `delegators`. +pub const ARG_DELEGATORS: &str = "delegators"; /// Named constant for `reservations`. pub const ARG_RESERVATIONS: &str = "reservations"; /// Named constant for `validator_purse`. diff --git a/types/src/system/auction/entry_points.rs b/types/src/system/auction/entry_points.rs index b7aba34c00..bdb708981f 100644 --- a/types/src/system/auction/entry_points.rs +++ b/types/src/system/auction/entry_points.rs @@ -13,8 +13,8 @@ use alloc::boxed::Box; use super::{ Reservation, ARG_DELEGATORS, ARG_MAXIMUM_DELEGATION_AMOUNT, ARG_MINIMUM_DELEGATION_AMOUNT, - ARG_NEW_PUBLIC_KEY, ARG_REWARDS_MAP, METHOD_ADD_RESERVATIONS, METHOD_CANCEL_RESERVATIONS, - METHOD_CHANGE_BID_PUBLIC_KEY, + ARG_NEW_PUBLIC_KEY, ARG_RESERVATIONS, ARG_REWARDS_MAP, METHOD_ADD_RESERVATIONS, + METHOD_CANCEL_RESERVATIONS, METHOD_CHANGE_BID_PUBLIC_KEY, }; /// Creates auction contract entry points. @@ -172,7 +172,7 @@ pub fn auction_entry_points() -> EntryPoints { let entry_point = EntryPoint::new( METHOD_ADD_RESERVATIONS, vec![Parameter::new( - ARG_DELEGATORS, + ARG_RESERVATIONS, CLType::List(Box::new(Reservation::cl_type())), )], CLType::Unit, From c273256380b953938cf121b98d3cc882eee161e5 Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Sun, 28 Jul 2024 09:19:48 +0200 Subject: [PATCH 36/38] Format contracts --- .../contracts/client/add-reservations/src/main.rs | 4 ++-- .../contracts/client/cancel-reservations/src/main.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/smart_contracts/contracts/client/add-reservations/src/main.rs b/smart_contracts/contracts/client/add-reservations/src/main.rs index f586a26f67..af1ebed740 100644 --- a/smart_contracts/contracts/client/add-reservations/src/main.rs +++ b/smart_contracts/contracts/client/add-reservations/src/main.rs @@ -7,7 +7,7 @@ use alloc::vec::Vec; use casper_contract::contract_api::runtime; use casper_types::{ - system::auction::{self, DelegationRate, Reservation}, + system::auction::{Reservation, ARG_RESERVATIONS}, PublicKey, }; @@ -21,7 +21,7 @@ fn add_reservations(reservations: Vec) { // Issues an add_reservations request to the auction contract. #[no_mangle] pub extern "C" fn call() { - let reservations: Vec = runtime::get_named_arg(auction::ARG_RESERVATIONS); + let reservations: Vec = runtime::get_named_arg(ARG_RESERVATIONS); add_reservations(reservations); } diff --git a/smart_contracts/contracts/client/cancel-reservations/src/main.rs b/smart_contracts/contracts/client/cancel-reservations/src/main.rs index 72d22edb49..2bf1ba6d18 100644 --- a/smart_contracts/contracts/client/cancel-reservations/src/main.rs +++ b/smart_contracts/contracts/client/cancel-reservations/src/main.rs @@ -7,7 +7,7 @@ use alloc::vec::Vec; use casper_contract::contract_api::runtime; use casper_types::{ - system::auction::{self, DelegationRate}, + system::auction::{DelegationRate, ARG_DELEGATORS, ARG_VALIDATOR}, PublicKey, }; @@ -21,8 +21,8 @@ fn cancel_reservations(_validator: PublicKey, _delegators: Vec) { // Issues a cancel_reservations request to the auction contract. #[no_mangle] pub extern "C" fn call() { - let delegators: Vec = runtime::get_named_arg(auction::ARG_DELEGATORS); - let validator = runtime::get_named_arg(auction::ARG_VALIDATOR); + let delegators: Vec = runtime::get_named_arg(ARG_DELEGATORS); + let validator = runtime::get_named_arg(ARG_VALIDATOR); cancel_reservations(validator, delegators); } From 89ea7cd58640eabeb1607356f36703fae3dd017c Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Sun, 28 Jul 2024 11:13:23 +0200 Subject: [PATCH 37/38] Format --- .../contracts/client/add-reservations/src/main.rs | 7 ++----- .../contracts/client/cancel-reservations/src/main.rs | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/smart_contracts/contracts/client/add-reservations/src/main.rs b/smart_contracts/contracts/client/add-reservations/src/main.rs index af1ebed740..516c51b89d 100644 --- a/smart_contracts/contracts/client/add-reservations/src/main.rs +++ b/smart_contracts/contracts/client/add-reservations/src/main.rs @@ -6,12 +6,9 @@ extern crate alloc; use alloc::vec::Vec; use casper_contract::contract_api::runtime; -use casper_types::{ - system::auction::{Reservation, ARG_RESERVATIONS}, - PublicKey, -}; +use casper_types::system::auction::{Reservation, ARG_RESERVATIONS}; -fn add_reservations(reservations: Vec) { +fn add_reservations(_reservations: Vec) { todo!(); } diff --git a/smart_contracts/contracts/client/cancel-reservations/src/main.rs b/smart_contracts/contracts/client/cancel-reservations/src/main.rs index 2bf1ba6d18..112f25bfd6 100644 --- a/smart_contracts/contracts/client/cancel-reservations/src/main.rs +++ b/smart_contracts/contracts/client/cancel-reservations/src/main.rs @@ -7,7 +7,7 @@ use alloc::vec::Vec; use casper_contract::contract_api::runtime; use casper_types::{ - system::auction::{DelegationRate, ARG_DELEGATORS, ARG_VALIDATOR}, + system::auction::{ARG_DELEGATORS, ARG_VALIDATOR}, PublicKey, }; From f8bb26bbd3d3e7d8f8fd1e7eac7aa8ef59b79e10 Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Wed, 14 Aug 2024 13:52:04 +0200 Subject: [PATCH 38/38] Adjust expected faucet costs. --- .../tests/src/test/explorer/faucet.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/execution_engine_testing/tests/src/test/explorer/faucet.rs b/execution_engine_testing/tests/src/test/explorer/faucet.rs index 2d169c3712..54c400a5de 100644 --- a/execution_engine_testing/tests/src/test/explorer/faucet.rs +++ b/execution_engine_testing/tests/src/test/explorer/faucet.rs @@ -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]);