Skip to content

Commit

Permalink
agave validator example
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed Apr 6, 2024
1 parent 77e2439 commit ab1396d
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 69 deletions.
21 changes: 1 addition & 20 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ members = [
"agave/program-cache",
"agave/svm",
"agave/sysvar-cache",
"agave/validator",
"solana/compute-budget",
"solana/runtime",
"solana/svm",
]

exclude = ["svm/tests/example-programs"]

resolver = "2"

[workspace.package]
Expand All @@ -22,22 +21,4 @@ license = "Apache-2.0"
edition = "2021"

[workspace.dependencies]
assert_matches = "1.5.0"
base64 = "0.22.0"
bincode = "1.3.3"
eager = "0.1.0"
enum-iterator = "1.5.0"
itertools = "0.10.5"
libc = "0.2.153"
libsecp256k1 = "0.6.0"
log = "0.4.21"
num-derive = "0.4"
num-traits = "0.2"
percentage = "0.1.0"
rand = "0.8.5"
rustc_version = "0.4"
serde = "1.0.197"
solana-sdk = { git = "https://github.com/anza-xyz/agave" }
solana_rbpf = "=0.8.0"
test-case = "3.3.1"
thiserror = "1.0.58"
29 changes: 19 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,27 @@ runtime that makes use of an SVM. However, notice that this is all done with
https://github.com/buffalojoec/modular-svm/blob/d52d0d34a5ce9e8fcda1153ff45934ab9721a310/solana/runtime/src/specification.rs#L10-L33

Meanwhile, the Agave runtime is now an _implementation_ (`agave-runtime`), and
it simply implements the `solana-runtime` interface by also providing an SVM
implementation (`agave-svm`) to be compliant.
it simply implements the `solana-runtime` interface, but **without specifying
a specific SVM implementation**.

https://github.com/buffalojoec/modular-svm/blob/d52d0d34a5ce9e8fcda1153ff45934ab9721a310/agave/runtime/src/lib.rs#L19-L52

The beautiful thing here is that another SVM could easily be plugged into
Agave's runtime implementation. Anyone could configure an Agave node, then write
an adapter for some other SVM implementation and plug it in right here 👆.
The beautiful thing here is that any SVM could easily be plugged into Agave's
runtime implementation. Anyone could configure an Agave node, then write an
adapter for some other SVM implementation and plug it in right here.

Note also the decoupling and modularization of the type crates, some of which
are specification-wide (`solana-compute-budget`) and some of which are
implementation-specific (`agave-program-cache`).
https://github.com/buffalojoec/modular-svm/blob/d52d0d34a5ce9e8fcda1153ff45934ab9721a310/agave/validator/src/lib.rs#L19-L52

Although metrics are not demonstrated here (yet), the idea is that they would
reside in one's implementation, and be vended back up to the callers.
🔑 🔑 A huge advantage with this arrangement is the fact that consensus-breaking
changes would reside in the specification-level, guarded by SIMDs, while
developers could more freely adjust implementation-level code and ship new
versions without worrying about partitioning the network.

Other important notes:

- This demo uses lightweight "leaf node" crates for types
(ie. `solana-compute-budget`).
- Some leaf node crates are specification-wide (ie. `solana-compute-budget`)
while others are implementation-specific (ie. `agave-program-cache`).
- Although metrics are not demonstrated here (yet), the idea is that they would
reside in one's implementation, and be vended back up to the callers.
9 changes: 5 additions & 4 deletions agave/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Agave Implementations

```
runtime
|-- svm
|-- program-cache
|-- sysvar-cache
validator
|-- runtime
|-- svm
|-- program-cache
|-- sysvar-cache
```
1 change: 0 additions & 1 deletion agave/program-cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ edition = { workspace = true }

[dependencies]
solana-sdk = { workspace = true }
solana_rbpf = { workspace = true }
18 changes: 18 additions & 0 deletions agave/runtime/src/batch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use {
solana_runtime::specification::TransactionBatch,
solana_sdk::transaction::{self, SanitizedTransaction},
std::borrow::Cow,
};

/// A transaction batch, as defined by the Agave Validator Runtime.
pub struct AgaveTransactionBatch<'a> {
pub lock_results: Vec<transaction::Result<()>>,
pub sanitized_txs: Cow<'a, [SanitizedTransaction]>,
pub needs_unlock: bool,
}

impl TransactionBatch for AgaveTransactionBatch<'_> {
fn sanitized_txs(&self) -> &[SanitizedTransaction] {
&self.sanitized_txs
}
}
46 changes: 13 additions & 33 deletions agave/runtime/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,24 @@
//! Agave Validator Runtime Implementation.

mod callbacks;
mod batch;

use {
crate::callbacks::AgaveValidatorRuntimeTransactionProcessingCallback,
agave_program_cache::ForkGraph,
agave_svm::AgaveTransactionBatchProcessor,
solana_runtime::specification::{
LoadAndExecuteTransactionsOutput, TransactionBatch, ValidatorRuntime,
},
solana_sdk::transaction::{self, SanitizedTransaction},
std::borrow::Cow,
crate::batch::AgaveTransactionBatch,
solana_runtime::specification::{LoadAndExecuteTransactionsOutput, ValidatorRuntime},
solana_svm::specification::TransactionBatchProcessor,
};

type AgaveTransactionBatchProcessorWithCallback<FG> =
AgaveTransactionBatchProcessor<AgaveValidatorRuntimeTransactionProcessingCallback, FG>;

/// The Agave Validator Runtime.
pub struct AgaveValidatorRuntime<FG: ForkGraph> {
pub batch_processor: AgaveTransactionBatchProcessorWithCallback<FG>,
pub struct AgaveValidatorRuntime<BP: TransactionBatchProcessor> {
/// SVM-agnostic batch processor.
pub batch_processor: BP,
}

/// Agave Validator Runtime Implementation.
impl<'a, FG: ForkGraph>
ValidatorRuntime<AgaveTransactionBatch<'a>, AgaveTransactionBatchProcessorWithCallback<FG>>
for AgaveValidatorRuntime<FG>
/// Agave Validator Runtime Base Implementation.
impl<'a, BP: TransactionBatchProcessor> ValidatorRuntime<AgaveTransactionBatch<'a>, BP>
for AgaveValidatorRuntime<BP>
{
/// Get the batch processor.
fn batch_processor(&self) -> &AgaveTransactionBatchProcessorWithCallback<FG> {
fn batch_processor(&self) -> &BP {
&self.batch_processor
}

Expand All @@ -39,6 +30,8 @@ impl<'a, FG: ForkGraph>
/*
* MOCK.
*/
let _batch_processor = self.batch_processor();
//
LoadAndExecuteTransactionsOutput {
loaded_transactions: vec![],
execution_results: vec![],
Expand All @@ -50,16 +43,3 @@ impl<'a, FG: ForkGraph>
}
}
}

/// A transaction batch, as defined by the Agave Validator Runtime.
pub struct AgaveTransactionBatch<'a> {
pub lock_results: Vec<transaction::Result<()>>,
pub sanitized_txs: Cow<'a, [SanitizedTransaction]>,
pub needs_unlock: bool,
}

impl TransactionBatch for AgaveTransactionBatch<'_> {
fn sanitized_txs(&self) -> &[SanitizedTransaction] {
&self.sanitized_txs
}
}
16 changes: 16 additions & 0 deletions agave/validator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "agave-validator"
description = "Agave Validator"
version = { workspace = true }
authors = { workspace = true }
repository = { workspace = true }
homepage = { workspace = true }
license = { workspace = true }
edition = { workspace = true }

[dependencies]
agave-program-cache = { path = "../program-cache" }
agave-runtime = { path = "../runtime" }
agave-svm = { path = "../svm" }
solana-svm = { path = "../../solana/svm" }
solana-sdk = { workspace = true }
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use {
std::sync::Arc,
};

/// Simply a mock callback implementation for Agave Validator Runtime.
/// Simply a mock runtime callback implementation for the Agave Validator.
pub struct AgaveValidatorRuntimeTransactionProcessingCallback;

impl TransactionProcessingCallback for AgaveValidatorRuntimeTransactionProcessingCallback {
Expand Down
21 changes: 21 additions & 0 deletions agave/validator/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! Agave Validator.

mod callbacks;

use {
crate::callbacks::AgaveValidatorRuntimeTransactionProcessingCallback,
agave_program_cache::ForkGraph, agave_runtime::AgaveValidatorRuntime,
agave_svm::AgaveTransactionBatchProcessor,
};

// This is a grossly over-simplified demonstration of an adapter, bridging the
// SVM-agnostic Agave runtime implementation with the Agave SVM implementation.
// Ideally, this would instead manifest as some module that could be easily
// replaced if another SVM implementation were to be used.
type Svm<FG> =
AgaveTransactionBatchProcessor<AgaveValidatorRuntimeTransactionProcessingCallback, FG>;

/// A mock Agave Validator.
pub struct AgaveValidator<FG: ForkGraph> {
pub runtime: AgaveValidatorRuntime<Svm<FG>>,
}

0 comments on commit ab1396d

Please sign in to comment.