Skip to content

Commit 5686133

Browse files
authored
Merge pull request #413 from filecoin-project/asr/run-nv21
Support nv21
2 parents a458f63 + b4f015d commit 5686133

File tree

7 files changed

+55
-78
lines changed

7 files changed

+55
-78
lines changed

cgo/extern.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@ import (
1111
"github.com/filecoin-project/go-address"
1212

1313
"github.com/filecoin-project/go-state-types/abi"
14-
"github.com/filecoin-project/go-state-types/crypto"
1514
)
1615

1716
//export cgo_extern_get_chain_randomness
1817
func cgo_extern_get_chain_randomness(
19-
handle C.uint64_t, pers C.int64_t, round C.int64_t,
20-
entropy C.buf_t, entropyLen C.int32_t,
18+
handle C.uint64_t, round C.int64_t,
2119
output C.buf_t,
2220
) (res C.int32_t) {
2321
defer func() {
@@ -33,11 +31,11 @@ func cgo_extern_get_chain_randomness(
3331
return ErrInvalidHandle
3432
}
3533

36-
rand, err := externs.GetChainRandomness(ctx, crypto.DomainSeparationTag(pers), abi.ChainEpoch(round), C.GoBytes(unsafe.Pointer(entropy), entropyLen))
34+
rand, err := externs.GetChainRandomness(ctx, abi.ChainEpoch(round))
3735

3836
switch err {
3937
case nil:
40-
copy(out[:], rand)
38+
copy(out[:], rand[:])
4139
return 0
4240
default:
4341
return ErrIO
@@ -46,8 +44,7 @@ func cgo_extern_get_chain_randomness(
4644

4745
//export cgo_extern_get_beacon_randomness
4846
func cgo_extern_get_beacon_randomness(
49-
handle C.uint64_t, pers C.int64_t, round C.int64_t,
50-
entropy C.buf_t, entropyLen C.int32_t,
47+
handle C.uint64_t, round C.int64_t,
5148
output C.buf_t,
5249
) (res C.int32_t) {
5350
defer func() {
@@ -63,11 +60,11 @@ func cgo_extern_get_beacon_randomness(
6360
return ErrInvalidHandle
6461
}
6562

66-
rand, err := externs.GetBeaconRandomness(ctx, crypto.DomainSeparationTag(pers), abi.ChainEpoch(round), C.GoBytes(unsafe.Pointer(entropy), entropyLen))
63+
rand, err := externs.GetBeaconRandomness(ctx, abi.ChainEpoch(round))
6764

6865
switch err {
6966
case nil:
70-
copy(out[:], rand)
67+
copy(out[:], rand[:])
7168
return 0
7269
default:
7370
return ErrIO

cgo/interface.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55

66
"github.com/filecoin-project/go-address"
77
"github.com/filecoin-project/go-state-types/abi"
8-
"github.com/filecoin-project/go-state-types/crypto"
98
"github.com/ipfs/go-cid"
109
blockstore "github.com/ipfs/go-ipfs-blockstore"
1110
)
@@ -29,8 +28,8 @@ const (
2928
)
3029

3130
type Externs interface {
32-
GetChainRandomness(ctx context.Context, personalization crypto.DomainSeparationTag, epoch abi.ChainEpoch, entropy []byte) ([]byte, error)
33-
GetBeaconRandomness(ctx context.Context, personalization crypto.DomainSeparationTag, epoch abi.ChainEpoch, entropy []byte) ([]byte, error)
31+
GetChainRandomness(ctx context.Context, epoch abi.ChainEpoch) ([32]byte, error)
32+
GetBeaconRandomness(ctx context.Context, epoch abi.ChainEpoch) ([32]byte, error)
3433
VerifyConsensusFault(ctx context.Context, h1, h2, extra []byte) (*ConsensusFault, int64)
3534
TipsetCid(ctx context.Context, epoch abi.ChainEpoch) (cid.Cid, error)
3635

rust/Cargo.lock

Lines changed: 35 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ anyhow = "1.0.23"
3333
serde_json = "1.0.46"
3434
rust-gpu-tools = { version = "0.6", optional = true, default-features = false }
3535
fr32 = { version = "~6.0", default-features = false }
36-
fvm3 = { package = "fvm", version = "~3.5.0", default-features = false }
37-
fvm3_shared = { package = "fvm_shared", version = "~3.4.0" }
38-
fvm2 = { package = "fvm", version = "~2.5", default-features = false }
36+
fvm3 = { package = "fvm", version = "~3.6.0", default-features = false, features = ["nv21-dev"] }
37+
fvm3_shared = { package = "fvm_shared", version = "~3.5.0" }
38+
fvm2 = { package = "fvm", version = "~2.6", default-features = false }
3939
fvm2_shared = { package = "fvm_shared", version = "~2.5" }
4040
fvm_ipld_encoding = "0.4.0"
4141
fvm_ipld_blockstore = "0.2.0"

rust/src/fvm/cgo/externs.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,13 @@ extern "C" {
2828

2929
pub fn cgo_extern_get_chain_randomness(
3030
handle: u64,
31-
pers: i64,
3231
round: i64,
33-
entropy: *const u8,
34-
entropy_len: i32,
3532
randomness: *mut [u8; 32],
3633
) -> i32;
3734

3835
pub fn cgo_extern_get_beacon_randomness(
3936
handle: u64,
40-
pers: i64,
4137
round: i64,
42-
entropy: *const u8,
43-
entropy_len: i32,
4438
randomness: *mut [u8; 32],
4539
) -> i32;
4640

rust/src/fvm/engine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl TryFrom<u32> for EngineVersion {
7171
fn try_from(value: u32) -> Result<Self, Self::Error> {
7272
match value {
7373
16 | 17 => Ok(EngineVersion::V1),
74-
18 | 19 | 20 => Ok(EngineVersion::V2),
74+
18 | 19 | 20 | 21 => Ok(EngineVersion::V2),
7575
_ => return Err(anyhow!("network version not supported")),
7676
}
7777
}

rust/src/fvm/externs.rs

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,10 @@ impl CgoExterns {
3434
}
3535

3636
impl Rand3 for CgoExterns {
37-
fn get_chain_randomness(
38-
&self,
39-
pers: i64,
40-
round: ChainEpoch,
41-
entropy: &[u8],
42-
) -> anyhow::Result<[u8; 32]> {
37+
fn get_chain_randomness(&self, round: ChainEpoch) -> anyhow::Result<[u8; 32]> {
4338
unsafe {
4439
let mut buf = [0u8; 32];
45-
match cgo_extern_get_chain_randomness(
46-
self.handle,
47-
pers,
48-
round,
49-
entropy.as_ptr(),
50-
entropy.len() as i32,
51-
&mut buf,
52-
) {
40+
match cgo_extern_get_chain_randomness(self.handle, round, &mut buf) {
5341
0 => Ok(buf),
5442
r @ 1.. => panic!("invalid return value from has: {}", r),
5543
x if x == FvmError::InvalidHandle as i32 => {
@@ -63,22 +51,10 @@ impl Rand3 for CgoExterns {
6351
}
6452
}
6553

66-
fn get_beacon_randomness(
67-
&self,
68-
pers: i64,
69-
round: ChainEpoch,
70-
entropy: &[u8],
71-
) -> anyhow::Result<[u8; 32]> {
54+
fn get_beacon_randomness(&self, round: ChainEpoch) -> anyhow::Result<[u8; 32]> {
7255
unsafe {
7356
let mut buf = [0u8; 32];
74-
match cgo_extern_get_beacon_randomness(
75-
self.handle,
76-
pers,
77-
round,
78-
entropy.as_ptr(),
79-
entropy.len() as i32,
80-
&mut buf,
81-
) {
57+
match cgo_extern_get_beacon_randomness(self.handle, round, &mut buf) {
8258
0 => Ok(buf),
8359
r @ 1.. => panic!("invalid return value from has: {}", r),
8460
x if x == FvmError::InvalidHandle as i32 => {
@@ -94,22 +70,12 @@ impl Rand3 for CgoExterns {
9470
}
9571

9672
impl Rand2 for CgoExterns {
97-
fn get_chain_randomness(
98-
&self,
99-
pers: i64,
100-
round: ChainEpoch,
101-
entropy: &[u8],
102-
) -> anyhow::Result<[u8; 32]> {
103-
Rand3::get_chain_randomness(self, pers, round, entropy)
73+
fn get_chain_randomness(&self, round: ChainEpoch) -> anyhow::Result<[u8; 32]> {
74+
Rand3::get_chain_randomness(self, round)
10475
}
10576

106-
fn get_beacon_randomness(
107-
&self,
108-
pers: i64,
109-
round: ChainEpoch,
110-
entropy: &[u8],
111-
) -> anyhow::Result<[u8; 32]> {
112-
Rand3::get_beacon_randomness(self, pers, round, entropy)
77+
fn get_beacon_randomness(&self, round: ChainEpoch) -> anyhow::Result<[u8; 32]> {
78+
Rand3::get_beacon_randomness(self, round)
11379
}
11480
}
11581

0 commit comments

Comments
 (0)