Skip to content

Commit

Permalink
rename "base" fork to "fontier"
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume Ballet <[email protected]>
  • Loading branch information
gballet committed Sep 2, 2024
1 parent cafa3b1 commit cc29ef9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/blockchain/fork.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const lib = @import("../lib.zig");
const Hash32 = lib.types.Hash32;
const Fork = @This();
pub const base = @import("./forks/base.zig");
pub const frontier = @import("./forks/frontier.zig");
pub const prague = @import("./forks/prague.zig");

vtable: *const VTable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const base_fork_vtable = Fork.VTable{
.deinit = deinit,
};

const BaseFork = struct {
const FrontierFork = struct {
const Self = @This();

fork: Fork = .{
Expand All @@ -27,7 +27,7 @@ const BaseFork = struct {
};

fn update_parent_block_hash(self: *Fork, block_num: u64, hash: Hash32) anyerror!void {
var base_fork: *BaseFork = @fieldParentPtr("fork", self);
var base_fork: *FrontierFork = @fieldParentPtr("fork", self);
if (block_num != base_fork.next_block_hash_index) {
return error.NonSequentialParentUpdate;
}
Expand All @@ -37,22 +37,22 @@ fn update_parent_block_hash(self: *Fork, block_num: u64, hash: Hash32) anyerror!
}

fn get_parent_block_hash(self: *Fork, block_num: u64) !Hash32 {
const base_fork: *BaseFork = @fieldParentPtr("fork", self);
const base_fork: *FrontierFork = @fieldParentPtr("fork", self);
if (block_num > base_fork.next_block_hash_index or block_num + base_fork.block_hashes.len < base_fork.next_block_hash_index) {
return std.mem.zeroes(Hash32);
}

return base_fork.block_hashes[block_num % base_fork.block_hashes.len];
}

pub fn newBaseFork(allocator: std.mem.Allocator) !*Fork {
var base_fork = try allocator.create(BaseFork);
pub fn newFrontierFork(allocator: std.mem.Allocator) !*Fork {
var base_fork = try allocator.create(FrontierFork);
base_fork.init();
base_fork.allocator = allocator;
return &base_fork.fork;
}

fn deinit(self: *Fork) void {
var base_fork: *BaseFork = @fieldParentPtr("fork", self);
var base_fork: *FrontierFork = @fieldParentPtr("fork", self);
base_fork.allocator.destroy(base_fork);
}
2 changes: 1 addition & 1 deletion src/tests/custom_tests.zig
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ test "create contract" {

// Configure an EVM execution enviroment for a block from this coinbase.
const env: Environment = .{
.fork = try Fork.base.newBaseFork(allocator),
.fork = try Fork.frontier.newFrontierFork(allocator),
.origin = coinbase,
.coinbase = coinbase,
.number = 100,
Expand Down
2 changes: 1 addition & 1 deletion src/tests/spec_tests.zig
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub const FixtureTest = struct {
var out = try allocator.alloc(u8, self.genesisRLP.len / 2);
var rlp_bytes = try std.fmt.hexToBytes(out, self.genesisRLP[2..]);
const parent_block = try Block.decode(allocator, rlp_bytes);
var chain = try blockchain.Blockchain.init(allocator, config.ChainId.Mainnet, &statedb, parent_block.header, try Fork.base.newBaseFork(allocator));
var chain = try blockchain.Blockchain.init(allocator, config.ChainId.Mainnet, &statedb, parent_block.header, try Fork.frontier.newFrontierFork(allocator));

// Execute blocks.
for (self.blocks) |encoded_block| {
Expand Down

0 comments on commit cc29ef9

Please sign in to comment.