-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add skeleton types types for auctions #1472
Changes from 3 commits
1928cd8
09522f0
2d1284d
18d016a
96bbff8
5fee62b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
use crate::{state::FeeAmount, NamespaceId, Transaction}; | ||
use hotshot_types::data::ViewNumber; | ||
use std::num::NonZeroU64; | ||
|
||
/// State Machine for Auction | ||
#[derive(Clone, Copy)] | ||
struct Auction { | ||
/// current phase. | ||
phase: AuctionPhase, | ||
/// A structure to find which Phase should be the current one. | ||
// This could probably be an enum with some restructuring. | ||
possible_phases: [AuctionPhase; 3], | ||
} | ||
|
||
impl Auction { | ||
fn update(mut self, view: ViewNumber) { | ||
self.phase = self | ||
.possible_phases | ||
.into_iter() | ||
.find(|phase| (view > phase.start && view < phase.end)) | ||
.unwrap(); | ||
} | ||
fn recv_bid(&self, view: ViewNumber, bid: BidTx) { | ||
self.update(view); | ||
match self.phase.kind { | ||
AuctionPhaseKind::Bid => self.send_txn(bid.as_txn()), | ||
_ => unimplemented!(), | ||
} | ||
} | ||
fn send_txn(&self, txn: Transaction) { | ||
unimplemented!(); | ||
} | ||
} | ||
|
||
// - needs to be configured in genesis block | ||
// - needs to be updatable | ||
/// Configuration for the auction system | ||
struct AuctionConfig { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can see in a very generic way why we need this information, but I'm having trouble reasoning about how we will actually use it. I feel like we will need to receive an event announcing the start of a phase. And from there we can use this to calculate the view at which that phase will end. Are there indeterminate spans between phases? if the end of one phase == start of next then we would only need the start of the first phase on the chain, which could just be a constant (or come from config). |
||
bid_phase_num_views: NonZeroU64, | ||
auction_phase_num_views: NonZeroU64, | ||
sequencing_phase_num_views: NonZeroU64, | ||
} | ||
|
||
/// Uniquely identifies an auction for sequencing rights of namespaces in the network | ||
#[derive(Clone, Copy)] | ||
struct AuctionId(u64); | ||
|
||
/// Uniquely identifies one auction phase for a specific auction | ||
#[derive(Clone, Copy)] | ||
struct AuctionPhaseId(AuctionId, AuctionPhaseKind); | ||
|
||
/// Describes one auction phase for a specific auction | ||
#[derive(Clone, Copy)] | ||
struct AuctionPhase { | ||
id: AuctionPhaseId, | ||
kind: AuctionPhaseKind, | ||
start: ViewNumber, | ||
tbro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end: ViewNumber, | ||
} | ||
|
||
/// Describes the 3 kinds of phases an active auction can be in | ||
#[derive(Clone, Copy)] | ||
enum AuctionPhaseKind { | ||
Bid, | ||
Assign, | ||
Sequence, | ||
} | ||
|
||
struct Signature; | ||
|
||
/// A transaction to bid for the sequencing rights of a namespace | ||
struct BidTx { | ||
auction: AuctionId, | ||
amount: FeeAmount, | ||
namespace: NamespaceId, | ||
nonce: Nonce, | ||
signature: Signature, | ||
} | ||
|
||
impl BidTx { | ||
// maybe better implemented as a From on Transaction | ||
fn as_txn(&self) -> Transaction { | ||
unimplemented!(); | ||
} | ||
} | ||
|
||
/// A solution to one auction of sequencing rights for namespaces | ||
struct AuctionResultTx { | ||
auction: AuctionId, | ||
nonce: Nonce, | ||
winners: Vec<BidTx>, | ||
signature: Signature, | ||
} | ||
|
||
// Not sure if needed | ||
struct BidRefundTx { | ||
nonce: Nonce, | ||
txns_to_refund: Vec<BidTx>, | ||
signature: Signature, | ||
} | ||
|
||
/// Nonce for special (auction) transactions | ||
struct Nonce(u64); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod api; | ||
pub mod auction; | ||
pub mod block; | ||
pub mod catchup; | ||
mod chain_config; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rereading, I think the actions that will actually occur are validation and persistence.