Skip to content

Commit

Permalink
syscalls add method: VerifyReplicaUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
simlecode committed Jan 10, 2022
1 parent 6f9d241 commit a2b24b6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
19 changes: 14 additions & 5 deletions pkg/vm/vmcontext/runtime_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import (
"context"
"fmt"

"github.com/filecoin-project/venus/venus-shared/actors/aerrors"

"github.com/filecoin-project/venus/venus-shared/actors/builtin"

"github.com/ipfs/go-cid"
cbor2 "github.com/ipfs/go-ipld-cbor"
logging "github.com/ipfs/go-log/v2"
Expand All @@ -21,9 +17,17 @@ import (
"github.com/filecoin-project/go-state-types/network"
"github.com/filecoin-project/go-state-types/rt"
rt0 "github.com/filecoin-project/specs-actors/actors/runtime"
rt2 "github.com/filecoin-project/specs-actors/v2/actors/runtime"
rt3 "github.com/filecoin-project/specs-actors/v3/actors/runtime"
rt4 "github.com/filecoin-project/specs-actors/v4/actors/runtime"
rt5 "github.com/filecoin-project/specs-actors/v5/actors/runtime"
rt6 "github.com/filecoin-project/specs-actors/v6/actors/runtime"
rt7 "github.com/filecoin-project/specs-actors/v7/actors/runtime"

"github.com/filecoin-project/venus/pkg/vm/gas"
"github.com/filecoin-project/venus/pkg/vm/runtime"
"github.com/filecoin-project/venus/venus-shared/actors/aerrors"
"github.com/filecoin-project/venus/venus-shared/actors/builtin"
"github.com/filecoin-project/venus/venus-shared/types"
)

Expand All @@ -41,8 +45,13 @@ func init() {

var actorLog = logging.Logger("vm.actors")

var _ rt5.Runtime = (*runtimeAdapter)(nil)
var _ rt0.Runtime = (*runtimeAdapter)(nil)
var _ rt2.Runtime = (*runtimeAdapter)(nil)
var _ rt3.Runtime = (*runtimeAdapter)(nil)
var _ rt4.Runtime = (*runtimeAdapter)(nil)
var _ rt5.Runtime = (*runtimeAdapter)(nil)
var _ rt6.Runtime = (*runtimeAdapter)(nil)
var _ rt7.Runtime = (*runtimeAdapter)(nil)

type runtimeAdapter struct {
ctx *invocationContext
Expand Down
36 changes: 21 additions & 15 deletions pkg/vm/vmcontext/syscalls.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/network"
rt5 "github.com/filecoin-project/specs-actors/v5/actors/runtime"
proof5 "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof"
rt7 "github.com/filecoin-project/specs-actors/v7/actors/runtime"
proof7 "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof"
"github.com/ipfs/go-cid"

"github.com/filecoin-project/venus/pkg/crypto"
Expand All @@ -32,12 +32,13 @@ type SyscallsStateView interface {
type SyscallsImpl interface {
VerifySignature(ctx context.Context, view SyscallsStateView, signature crypto.Signature, signer address.Address, plaintext []byte) error
HashBlake2b(data []byte) [32]byte
ComputeUnsealedSectorCID(ctx context.Context, proof5 abi.RegisteredSealProof, pieces []abi.PieceInfo) (cid.Cid, error)
VerifySeal(ctx context.Context, info proof5.SealVerifyInfo) error
BatchVerifySeals(ctx context.Context, vis map[address.Address][]proof5.SealVerifyInfo) (map[address.Address][]bool, error)
VerifyAggregateSeals(aggregate proof5.AggregateSealVerifyProofAndInfos) error
VerifyPoSt(ctx context.Context, info proof5.WindowPoStVerifyInfo) error
VerifyConsensusFault(ctx context.Context, h1, h2, extra []byte, curEpoch abi.ChainEpoch, msg VmMessage, gasIpld cbornode.IpldStore, view SyscallsStateView, getter LookbackStateGetter) (*rt5.ConsensusFault, error)
ComputeUnsealedSectorCID(ctx context.Context, proof7 abi.RegisteredSealProof, pieces []abi.PieceInfo) (cid.Cid, error)
VerifySeal(ctx context.Context, info proof7.SealVerifyInfo) error
BatchVerifySeals(ctx context.Context, vis map[address.Address][]proof7.SealVerifyInfo) (map[address.Address][]bool, error)
VerifyAggregateSeals(aggregate proof7.AggregateSealVerifyProofAndInfos) error
VerifyReplicaUpdate(update proof7.ReplicaUpdateInfo) error
VerifyPoSt(ctx context.Context, info proof7.WindowPoStVerifyInfo) error
VerifyConsensusFault(ctx context.Context, h1, h2, extra []byte, curEpoch abi.ChainEpoch, msg VmMessage, gasIpld cbornode.IpldStore, view SyscallsStateView, getter LookbackStateGetter) (*rt7.ConsensusFault, error)
}

type syscalls struct {
Expand All @@ -50,7 +51,7 @@ type syscalls struct {
stateView SyscallsStateView
}

var _ rt5.Syscalls = (*syscalls)(nil)
var _ rt7.Syscalls = (*syscalls)(nil)

func (sys syscalls) VerifySignature(signature crypto.Signature, signer address.Address, plaintext []byte) error {
charge, err := sys.pricelist.OnVerifySignature(signature.Type, len(plaintext))
Expand All @@ -71,24 +72,24 @@ func (sys syscalls) ComputeUnsealedSectorCID(proof abi.RegisteredSealProof, piec
return sys.impl.ComputeUnsealedSectorCID(sys.vm.context, proof, pieces)
}

func (sys syscalls) VerifySeal(info proof5.SealVerifyInfo) error {
func (sys syscalls) VerifySeal(info proof7.SealVerifyInfo) error {
sys.gasTank.Charge(sys.pricelist.OnVerifySeal(info), "VerifySeal")
return sys.impl.VerifySeal(sys.vm.context, info)
}

func (sys syscalls) VerifyPoSt(info proof5.WindowPoStVerifyInfo) error {
func (sys syscalls) VerifyPoSt(info proof7.WindowPoStVerifyInfo) error {
sys.gasTank.Charge(sys.pricelist.OnVerifyPost(info), "VerifyWindowPoSt")
return sys.impl.VerifyPoSt(sys.vm.context, info)
}

func (sys syscalls) VerifyConsensusFault(h1, h2, extra []byte) (*rt5.ConsensusFault, error) {
func (sys syscalls) VerifyConsensusFault(h1, h2, extra []byte) (*rt7.ConsensusFault, error) {
sys.gasTank.Charge(sys.pricelist.OnVerifyConsensusFault(), "VerifyConsensusFault")
return sys.impl.VerifyConsensusFault(sys.vm.context, h1, h2, extra, sys.vm.currentEpoch, sys.vmMsg, sys.gasBlockStore, sys.stateView, sys.vm.vmOption.LookbackStateGetter)
}

var BatchSealVerifyParallelism = 2 * goruntime.NumCPU()

func (sys syscalls) BatchVerifySeals(vis map[address.Address][]proof5.SealVerifyInfo) (map[address.Address][]bool, error) {
func (sys syscalls) BatchVerifySeals(vis map[address.Address][]proof7.SealVerifyInfo) (map[address.Address][]bool, error) {
out := make(map[address.Address][]bool)

sema := make(chan struct{}, BatchSealVerifyParallelism)
Expand All @@ -100,7 +101,7 @@ func (sys syscalls) BatchVerifySeals(vis map[address.Address][]proof5.SealVerify

for i, s := range seals {
wg.Add(1)
go func(ma address.Address, ix int, svi proof5.SealVerifyInfo, res []bool) {
go func(ma address.Address, ix int, svi proof7.SealVerifyInfo, res []bool) {
defer wg.Done()
sema <- struct{}{}

Expand All @@ -120,7 +121,12 @@ func (sys syscalls) BatchVerifySeals(vis map[address.Address][]proof5.SealVerify
return out, nil
}

func (sys *syscalls) VerifyAggregateSeals(aggregate proof5.AggregateSealVerifyProofAndInfos) error {
func (sys *syscalls) VerifyAggregateSeals(aggregate proof7.AggregateSealVerifyProofAndInfos) error {
sys.gasTank.Charge(sys.pricelist.OnVerifyAggregateSeals(aggregate), "VerifyAggregateSeals")
return sys.impl.VerifyAggregateSeals(aggregate)
}

func (sys *syscalls) VerifyReplicaUpdate(update proof7.ReplicaUpdateInfo) error {
sys.gasTank.Charge(sys.pricelist.OnVerifyReplicaUpdate(update), "OnVerifyReplicaUpdate")
return sys.impl.VerifyReplicaUpdate(update)
}
2 changes: 1 addition & 1 deletion tools/gengen/util/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func NewGenesisGenerator(bs blockstore.Blockstore) *GenesisGenerator {

vmOption := vm.VmOption{
CircSupplyCalculator: csc,
NetworkVersion: network.Version15,
NetworkVersion: network.Version6,
LookbackStateGetter: vmcontext.LookbackStateGetterForTipset(context.TODO(), chainStore, chainFork, nil),
Rnd: chainRand,
BaseFee: abi.NewTokenAmount(InitialBaseFee),
Expand Down

0 comments on commit a2b24b6

Please sign in to comment.