Skip to content
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 initial support for pluggable syscalls #1922

Merged
merged 12 commits into from
Nov 22, 2023
Merged

Conversation

fridrik01
Copy link
Contributor

@fridrik01 fridrik01 commented Nov 15, 2023

See: #1787

This PR adds initial support for pluggable syscall by allowing us to extend the default kernel and add new custom syscalls through a new kernel.

The implementation does this by moving the global bind_syscall function into kernel via a SyscallHandler trait where each kernel needs to add their new syscalls.

The implementation uses Ambassador crate which automatically create stubs for delegating kernel implementations we are not overriding in new kernels, minimizing the code we need to write.

@codecov-commenter
Copy link

codecov-commenter commented Nov 15, 2023

Codecov Report

Merging #1922 (4f43657) into master (1200b8a) will decrease coverage by 0.19%.
The diff coverage is 40.34%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1922      +/-   ##
==========================================
- Coverage   75.64%   75.46%   -0.19%     
==========================================
  Files         153      156       +3     
  Lines       15120    15234     +114     
==========================================
+ Hits        11438    11496      +58     
- Misses       3682     3738      +56     
Files Coverage Δ
fvm/src/engine/mod.rs 80.90% <100.00%> (+0.15%) ⬆️
fvm/src/gas/price_list.rs 78.31% <ø> (-1.07%) ⬇️
fvm/src/lib.rs 46.42% <100.00%> (-0.94%) ⬇️
fvm/src/syscalls/actor.rs 89.91% <ø> (-5.62%) ⬇️
fvm/src/syscalls/crypto.rs 100.00% <ø> (+57.92%) ⬆️
sdk/src/actor.rs 0.00% <ø> (ø)
fvm/src/kernel/mod.rs 83.33% <83.33%> (ø)
fvm/src/syscalls/mod.rs 96.87% <97.67%> (-0.44%) ⬇️
fvm/src/kernel/default.rs 81.93% <79.77%> (+19.85%) ⬆️
fvm/src/syscalls/filecoin.rs 17.39% <17.39%> (ø)
... and 1 more

... and 6 files with indirect coverage changes

@fridrik01 fridrik01 force-pushed the pluggable-syscalls branch 3 times, most recently from ae8f628 to f689c46 Compare November 15, 2023 15:33
fvm/src/kernel/mod.rs Outdated Show resolved Hide resolved
@fridrik01 fridrik01 force-pushed the pluggable-syscalls branch 3 times, most recently from bc72b56 to a4f8261 Compare November 20, 2023 14:51
fvm/src/syscalls/mod.rs Outdated Show resolved Hide resolved
fvm/src/kernel/default.rs Show resolved Hide resolved
Comment on lines +47 to +51
pub caller: ActorID,
pub actor_id: ActorID,
pub method: MethodNum,
pub value_received: TokenAmount,
pub read_only: bool,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm starting to wonder how this will interact with testing. E.g., I want to support FilecoinKernel<TestKernel<DefaultKernel>>. Options include:

  1. Using accessor methods here. IIRC, we never actually change any of these fields (or the ones below), we just read them.
  2. Require that all kernels "deref" to some BaseKernel.
  3. Alternatively, require that all kernels expose some form of "invocation state"?

I think we can leave it alone for now, but I figured I'd comment on this in case you had any ideas.

fvm/src/kernel/mod.rs Outdated Show resolved Hide resolved
fvm/src/kernel/mod.rs Outdated Show resolved Hide resolved
fvm/src/kernel/mod.rs Outdated Show resolved Hide resolved
fvm/src/kernel/default.rs Outdated Show resolved Hide resolved
pub trait Kernel:
ActorOps
SyscallHandler<<Self as Kernel>::Kernel>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this? IMO:

  1. This really should be the other way around (kernels are syscall handlers).
  2. I'm not sure if we even need to care about that either. We can likely treat them as different things.

So, I think the SyscallHandler implementation changes to:

impl<K, T> SyscallHandler<K> for DefaultFilecoinKernel<T>
where
    K: Kernel,
    T: SyscallHandler<Self>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you suggesting removing SyscallHandler from the Kernel? How would we call the bind_syscalls on it when initializing the engine then, or am I misunderstanding?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was... but yeah, that might be even more annoying (we'd have to change all : Kernel constraints to : SyscallHandler or : Kernel + SyscallHandler. So, maybe later but not now.

fvm/src/kernel/mod.rs Outdated Show resolved Hide resolved
Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're going to want to re-think the traits here a bit, but I think this is at a nice stopping point where we can merge and iterate on master.

@@ -185,6 +172,100 @@ where
},
})
}

fn upgrade_actor<K: Kernel<CallManager = C>>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may make sense to move this, but can we wait for a new patch?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(or we can just leave it, we're going to have to refactor all this anyways)

self.0.machine()
}

fn send<K: Kernel<CallManager = C>>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. I hadn't realized we had moved this to the root trait (should have been more thorough when I reviewed that patch...). Having to manually delegate this is... annoying, but I guess we can fix it in a followup patch.

Really, I'm now convinced we need to refactor the entire Kernel trait stack.

@fridrik01 fridrik01 changed the title [WIP] Pluggable syscalls Add initial support for pluggable syscalls Nov 22, 2023
@fridrik01 fridrik01 marked this pull request as ready for review November 22, 2023 09:29
@fridrik01 fridrik01 merged commit 97b45db into master Nov 22, 2023
12 checks passed
@fridrik01 fridrik01 deleted the pluggable-syscalls branch November 22, 2023 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants