Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions plugin/evm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ func (vm *VM) CreateHandlers(context.Context) (map[string]http.Handler, error) {
warpSDKClient := vm.Network.NewClient(p2p.SignatureRequestHandlerID)
signatureAggregator := acp118.NewSignatureAggregator(vm.ctx.Log, warpSDKClient)

if err := handler.RegisterName("warp", warp.NewAPI(vm.ctx, vm.warpBackend, signatureAggregator, vm.requirePrimaryNetworkSigners)); err != nil {
if err := handler.RegisterName("warp", warp.NewAPI(vm.ctx, vm.warpBackend, signatureAggregator)); err != nil {
return nil, err
}
enabledAPIs = append(enabledAPIs, "warp")
Expand Down Expand Up @@ -1111,24 +1111,6 @@ func (vm *VM) rules(number *big.Int, time uint64) extras.Rules {
return *params.GetRulesExtra(ethrules)
}

// currentRules returns the chain rules for the current block.
func (vm *VM) currentRules() extras.Rules {
header := vm.eth.APIBackend.CurrentHeader()
return vm.rules(header.Number, header.Time)
}

// requirePrimaryNetworkSigners returns true if warp messages from the primary
// network must be signed by the primary network validators.
// This is necessary when the subnet is not validating the primary network.
func (vm *VM) requirePrimaryNetworkSigners() bool {
switch c := vm.currentRules().Precompiles[warpcontract.ContractAddress].(type) {
case *warpcontract.Config:
return c.RequirePrimaryNetworkSigners
default: // includes nil due to non-presence
return false
}
}

func (vm *VM) startContinuousProfiler() {
// If the profiler directory is empty, return immediately
// without creating or starting a continuous profiler.
Expand Down
20 changes: 8 additions & 12 deletions warp/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,22 @@ import (
"github.com/ava-labs/libevm/log"

warpprecompile "github.com/ava-labs/coreth/precompile/contracts/warp"
warpValidators "github.com/ava-labs/coreth/warp/validators"
)

var errNoValidators = errors.New("cannot aggregate signatures from subnet with no validators")

// API introduces snowman specific functionality to the evm
type API struct {
chainContext *snow.Context
backend Backend
signatureAggregator *acp118.SignatureAggregator
requirePrimaryNetworkSigners func() bool
chainContext *snow.Context
backend Backend
signatureAggregator *acp118.SignatureAggregator
}

func NewAPI(chainCtx *snow.Context, backend Backend, signatureAggregator *acp118.SignatureAggregator, requirePrimaryNetworkSigners func() bool) *API {
func NewAPI(chainCtx *snow.Context, backend Backend, signatureAggregator *acp118.SignatureAggregator) *API {
return &API{
backend: backend,
chainContext: chainCtx,
signatureAggregator: signatureAggregator,
requirePrimaryNetworkSigners: requirePrimaryNetworkSigners,
backend: backend,
chainContext: chainCtx,
signatureAggregator: signatureAggregator,
}
}

Expand Down Expand Up @@ -108,8 +105,7 @@ func (a *API) aggregateSignatures(ctx context.Context, unsignedMessage *warp.Uns
return nil, err
}

state := warpValidators.NewState(validatorState, a.chainContext.SubnetID, a.chainContext.ChainID, a.requirePrimaryNetworkSigners())
validatorSet, err := warp.GetCanonicalValidatorSetFromSubnetID(ctx, state, pChainHeight, subnetID)
validatorSet, err := warp.GetCanonicalValidatorSetFromSubnetID(ctx, validatorState, pChainHeight, subnetID)
if err != nil {
return nil, fmt.Errorf("failed to get validator set: %w", err)
}
Expand Down
Loading