Skip to content

Commit

Permalink
Add a wrapper Auction type w/ rudimentary state machine
Browse files Browse the repository at this point in the history
I'm probably going off on a limb, but its easier for me to think about
the types if there is some logic tying them together. Ultimately I
think we will expose a function to an event handler that will make the
gears turn. I believe `ViewNumber` can be passed in, and I'm guessing
`BidTx` we be as well.
  • Loading branch information
tbro committed May 16, 2024
1 parent 1928cd8 commit 09522f0
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion sequencer/src/auction.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,37 @@
use crate::{state::FeeAmount, NamespaceId};
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 if we we structure.
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
Expand All @@ -12,12 +42,15 @@ struct AuctionConfig {
}

/// 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,
Expand All @@ -26,6 +59,7 @@ struct AuctionPhase {
}

/// Describes the 3 kinds of phases an active auction can be in
#[derive(Clone, Copy)]
enum AuctionPhaseKind {
Bid,
Assign,
Expand All @@ -43,6 +77,13 @@ struct BidTx {
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,
Expand Down

0 comments on commit 09522f0

Please sign in to comment.