Skip to content

Commit

Permalink
feat(svm): initial sbfv1 virtual machine (#478)
Browse files Browse the repository at this point in the history
* initial svm implementation

* geyser: remove needless allocation in a test

* svm: include elf binary tests

* svm: fix up some comments

* svm: rename `registerFunction*` to `register*`

* svm: clean up a bit

* svm: fix some more comments

* svm: remove `test_input.hex`

* svm: don't leak if `getInstructions` fails

* svm: rework the Elf parser to parse in stages

* svm: remove confusing boolean

* svm: return an error if `addr != offset` while parsing ro

* address some final comments

* svm: revert files-as-structs usage

* svm: conform to style guide

* svm: rename files to lowercase

* svm: rename `ebpf.zig` to `sbpf.zig`

* svm: rename to use `self` pattern

---------

Co-authored-by: Drew Nutter <[email protected]>
  • Loading branch information
Rexicon226 and dnut authored Jan 15, 2025
1 parent fbc554e commit 7b961e8
Show file tree
Hide file tree
Showing 19 changed files with 4,127 additions and 10 deletions.
16 changes: 16 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub fn build(b: *Build) void {
const fuzz_step = b.step("fuzz", "Gossip fuzz testing");
const benchmark_step = b.step("benchmark", "Benchmark client");
const geyser_reader_step = b.step("geyser_reader", "Read data from geyser");
const svm_step = b.step("svm", "Run the SVM client");

// Dependencies
const dep_opts = .{ .target = target, .optimize = optimize };
Expand Down Expand Up @@ -215,6 +216,21 @@ pub fn build(b: *Build) void {
geyser_reader_exe_run.addArgs(b.args orelse &.{});
if (!no_run) geyser_reader_step.dependOn(&geyser_reader_exe_run.step);
if (no_run) geyser_reader_step.dependOn(&b.addInstallArtifact(geyser_reader_exe, .{}).step);

const svm_exe = b.addExecutable(.{
.name = "svm",
.root_source_file = b.path("src/svm/main.zig"),
.target = target,
.optimize = optimize,
.sanitize_thread = enable_tsan,
});
b.installArtifact(svm_exe);
svm_exe.root_module.addImport("sig", sig_mod);

const svm_exe_run = b.addRunArtifact(svm_exe);
svm_exe_run.addArgs(b.args orelse &.{});
if (!no_run) svm_step.dependOn(&svm_exe_run.step);
if (no_run) svm_step.dependOn(&b.addInstallArtifact(svm_exe, .{}).step);
}

const BlockstoreDB = enum {
Expand Down
Binary file added data/test-elfs/reloc_64_64_sbpfv1.so
Binary file not shown.
Binary file added data/test-elfs/reloc_64_relative_data_sbpfv1.so
Binary file not shown.
Binary file added data/test-elfs/reloc_64_relative_sbpfv1.so
Binary file not shown.
Binary file added data/test-elfs/rodata_section_sbpfv1.so
Binary file not shown.
Binary file added data/test-elfs/static_internal_call_sbpfv1.so
Binary file not shown.
Binary file added data/test-elfs/syscall_reloc_64_32.so
Binary file not shown.
6 changes: 2 additions & 4 deletions src/geyser/core.zig
Original file line number Diff line number Diff line change
Expand Up @@ -538,15 +538,13 @@ test "streaming accounts" {
pubkeys[i] = Pubkey.initRandom(random);
}

const exit = try allocator.create(std.atomic.Value(bool));
defer allocator.destroy(exit);
exit.* = std.atomic.Value(bool).init(false);
var exit = std.atomic.Value(bool).init(false);

// setup writer
var stream_writer = try GeyserWriter.init(
allocator,
sig.TEST_DATA_DIR ++ "stream_test.pipe",
exit,
&exit,
1 << 18,
);
defer stream_writer.deinit();
Expand Down
4 changes: 3 additions & 1 deletion src/sig.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ pub const prometheus = @import("prometheus/lib.zig");
pub const rand = @import("rand/rand.zig");
pub const rpc = @import("rpc/lib.zig");
pub const shred_network = @import("shred_network/lib.zig");
pub const svm = @import("svm/lib.zig");
pub const sync = @import("sync/lib.zig");
pub const trace = @import("trace/lib.zig");
pub const time = @import("time/lib.zig");
pub const trace = @import("trace/lib.zig");
pub const transaction_sender = @import("transaction_sender/lib.zig");
pub const utils = @import("utils/lib.zig");
pub const version = @import("version/version.zig");
Expand All @@ -31,6 +32,7 @@ pub const TEST_STATE_DIR = "data/test-state/";
pub const FUZZ_DATA_DIR = "data/fuzz-data/";
pub const BENCHMARK_RESULTS_DIR = "results/";
pub const GENESIS_DIR = "data/genesis-files/";
pub const ELF_DATA_DIR = "data/test-elfs/";

comptime {
// sig's global assertions/assumptions
Expand Down
Loading

0 comments on commit 7b961e8

Please sign in to comment.