Skip to content

Commit

Permalink
Remove proposervm signer + cert from snow.Context (ava-labs#2447)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshua-kim authored Jan 10, 2023
1 parent 10f4405 commit e38a148
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 93 deletions.
8 changes: 4 additions & 4 deletions chains/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,8 @@ func (m *manager) buildChain(chainParams ChainParameters, sb Subnet) (*chain, er

TeleporterSigner: teleporter.NewSigner(m.StakingBLSKey, chainParams.ID),

ValidatorState: m.validatorState,
StakingCertLeaf: m.StakingCert.Leaf,
StakingLeafSigner: m.StakingCert.PrivateKey.(crypto.Signer),
ChainDataDir: chainDataDir,
ValidatorState: m.validatorState,
ChainDataDir: chainDataDir,
},
DecisionAcceptor: m.DecisionAcceptorGroup,
ConsensusAcceptor: m.ConsensusAcceptorGroup,
Expand Down Expand Up @@ -934,6 +932,8 @@ func (m *manager) createSnowmanChain(
m.ApricotPhase4Time,
m.ApricotPhase4MinPChainHeight,
minBlockDelay,
m.StakingCert.PrivateKey.(crypto.Signer),
m.StakingCert.Leaf,
)

if m.MeterVMEnabled {
Expand Down
7 changes: 1 addition & 6 deletions snow/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
package snow

import (
"crypto"
"crypto/x509"
"sync"

"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -51,10 +49,7 @@ type Context struct {
TeleporterSigner teleporter.Signer

// snowman++ attributes
ValidatorState validators.State // interface for P-Chain validators
StakingLeafSigner crypto.Signer // block signer
StakingCertLeaf *x509.Certificate // block certificate

ValidatorState validators.State // interface for P-Chain validators
// Chain-specific directory where arbitrary data can be written
ChainDataDir string
}
Expand Down
11 changes: 8 additions & 3 deletions vms/proposervm/batched_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,14 @@ func initTestRemoteProposerVM(
}
}

proVM := New(coreVM, proBlkStartTime, 0, DefaultMinBlockDelay)
proVM := New(
coreVM,
proBlkStartTime,
0,
DefaultMinBlockDelay,
pTestCert.PrivateKey.(crypto.Signer),
pTestCert.Leaf,
)

valState := &validators.TestState{
T: t,
Expand Down Expand Up @@ -1013,8 +1020,6 @@ func initTestRemoteProposerVM(

ctx := snow.DefaultContextTest()
ctx.NodeID = ids.NodeIDFromCert(pTestCert.Leaf)
ctx.StakingCertLeaf = pTestCert.Leaf
ctx.StakingLeafSigner = pTestCert.PrivateKey.(crypto.Signer)
ctx.ValidatorState = valState

dummyDBManager := manager.NewMemDB(version.Semantic1_0_0)
Expand Down
4 changes: 2 additions & 2 deletions vms/proposervm/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,10 @@ func (p *postForkCommonComponents) buildChild(
parentID,
newTimestamp,
pChainHeight,
p.vm.ctx.StakingCertLeaf,
p.vm.stakingCertLeaf,
innerBlock.Bytes(),
p.vm.ctx.ChainID,
p.vm.ctx.StakingLeafSigner,
p.vm.stakingLeafSigner,
)
}
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions vms/proposervm/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ func TestPostForkCommonComponents_buildChild(t *testing.T) {
ChainVM: innerVM,
blockBuilderVM: innerBlockBuilderVM,
ctx: &snow.Context{
ValidatorState: vdrState,
Log: logging.NoLog{},
StakingCertLeaf: &x509.Certificate{},
StakingLeafSigner: pk,
ValidatorState: vdrState,
Log: logging.NoLog{},
},
Windower: windower,
Windower: windower,
stakingCertLeaf: &x509.Certificate{},
stakingLeafSigner: pk,
}

blk := &postForkCommonComponents{
Expand Down
40 changes: 20 additions & 20 deletions vms/proposervm/post_fork_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ func TestOracle_PostForkBlock_ImplementsInterface(t *testing.T) {
ids.Empty, // refer unknown parent
time.Time{},
0, // pChainHeight,
proVM.ctx.StakingCertLeaf,
proVM.stakingCertLeaf,
innerOracleBlk.Bytes(),
proVM.ctx.ChainID,
proVM.ctx.StakingLeafSigner,
proVM.stakingLeafSigner,
)
if err != nil {
t.Fatal("could not build stateless block")
Expand Down Expand Up @@ -153,10 +153,10 @@ func TestBlockVerify_PostForkBlock_ParentChecks(t *testing.T) {
ids.Empty, // refer unknown parent
childCoreBlk.Timestamp(),
pChainHeight,
proVM.ctx.StakingCertLeaf,
proVM.stakingCertLeaf,
childCoreBlk.Bytes(),
proVM.ctx.ChainID,
proVM.ctx.StakingLeafSigner,
proVM.stakingLeafSigner,
)
if err != nil {
t.Fatal("could not build stateless block")
Expand Down Expand Up @@ -268,10 +268,10 @@ func TestBlockVerify_PostForkBlock_TimestampChecks(t *testing.T) {
prntProBlk.ID(),
childCoreBlk.Timestamp(),
pChainHeight,
proVM.ctx.StakingCertLeaf,
proVM.stakingCertLeaf,
childCoreBlk.Bytes(),
proVM.ctx.ChainID,
proVM.ctx.StakingLeafSigner,
proVM.stakingLeafSigner,
)
if err != nil {
t.Fatal("could not build stateless block")
Expand Down Expand Up @@ -301,10 +301,10 @@ func TestBlockVerify_PostForkBlock_TimestampChecks(t *testing.T) {
prntProBlk.ID(),
beforeWinStart,
pChainHeight,
proVM.ctx.StakingCertLeaf,
proVM.stakingCertLeaf,
childCoreBlk.Bytes(),
proVM.ctx.ChainID,
proVM.ctx.StakingLeafSigner,
proVM.stakingLeafSigner,
)
if err != nil {
t.Fatal("could not build stateless block")
Expand All @@ -322,10 +322,10 @@ func TestBlockVerify_PostForkBlock_TimestampChecks(t *testing.T) {
prntProBlk.ID(),
atWindowStart,
pChainHeight,
proVM.ctx.StakingCertLeaf,
proVM.stakingCertLeaf,
childCoreBlk.Bytes(),
proVM.ctx.ChainID,
proVM.ctx.StakingLeafSigner,
proVM.stakingLeafSigner,
)
if err != nil {
t.Fatal("could not build stateless block")
Expand All @@ -343,10 +343,10 @@ func TestBlockVerify_PostForkBlock_TimestampChecks(t *testing.T) {
prntProBlk.ID(),
afterWindowStart,
pChainHeight,
proVM.ctx.StakingCertLeaf,
proVM.stakingCertLeaf,
childCoreBlk.Bytes(),
proVM.ctx.ChainID,
proVM.ctx.StakingLeafSigner,
proVM.stakingLeafSigner,
)
if err != nil {
t.Fatal("could not build stateless block")
Expand Down Expand Up @@ -379,10 +379,10 @@ func TestBlockVerify_PostForkBlock_TimestampChecks(t *testing.T) {
prntProBlk.ID(),
afterSubWinEnd,
pChainHeight,
proVM.ctx.StakingCertLeaf,
proVM.stakingCertLeaf,
childCoreBlk.Bytes(),
proVM.ctx.ChainID,
proVM.ctx.StakingLeafSigner,
proVM.stakingLeafSigner,
)
if err != nil {
t.Fatal("could not build stateless block")
Expand Down Expand Up @@ -465,10 +465,10 @@ func TestBlockVerify_PostForkBlock_PChainHeightChecks(t *testing.T) {
prntProBlk.ID(),
childCoreBlk.Timestamp(),
prntBlkPChainHeight-1,
proVM.ctx.StakingCertLeaf,
proVM.stakingCertLeaf,
childCoreBlk.Bytes(),
proVM.ctx.ChainID,
proVM.ctx.StakingLeafSigner,
proVM.stakingLeafSigner,
)
if err != nil {
t.Fatal("could not build stateless block")
Expand Down Expand Up @@ -673,10 +673,10 @@ func TestBlockVerify_PostForkBlockBuiltOnOption_PChainHeightChecks(t *testing.T)
parentBlk.ID(),
childCoreBlk.Timestamp(),
prntBlkPChainHeight-1,
proVM.ctx.StakingCertLeaf,
proVM.stakingCertLeaf,
childCoreBlk.Bytes(),
proVM.ctx.ChainID,
proVM.ctx.StakingLeafSigner,
proVM.stakingLeafSigner,
)
if err != nil {
t.Fatal("could not build stateless block")
Expand Down Expand Up @@ -1089,10 +1089,10 @@ func TestBlockVerify_PostForkBlock_ShouldBePostForkOption(t *testing.T) {
postForkOracleBlk.ID(),
postForkOracleBlk.Timestamp().Add(proposer.WindowDuration),
postForkOracleBlk.PChainHeight(),
proVM.ctx.StakingCertLeaf,
proVM.stakingCertLeaf,
oracleCoreBlk.opts[0].Bytes(),
proVM.ctx.ChainID,
proVM.ctx.StakingLeafSigner,
proVM.stakingLeafSigner,
)
if err != nil {
t.Fatal("failed to build new child block")
Expand Down
10 changes: 9 additions & 1 deletion vms/proposervm/post_fork_option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package proposervm
import (
"bytes"
"context"
"crypto"
"testing"
"time"

Expand Down Expand Up @@ -740,7 +741,14 @@ func TestOptionTimestampValidity(t *testing.T) {
// Restart the node.

ctx := proVM.ctx
proVM = New(coreVM, time.Time{}, 0, DefaultMinBlockDelay)
proVM = New(
coreVM,
time.Time{},
0,
DefaultMinBlockDelay,
pTestCert.PrivateKey.(crypto.Signer),
pTestCert.Leaf,
)

coreVM.InitializeF = func(
context.Context,
Expand Down
8 changes: 4 additions & 4 deletions vms/proposervm/pre_fork_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,10 @@ func TestBlockVerify_BlocksBuiltOnPreForkGenesis(t *testing.T) {
coreGenBlk.ID(),
coreBlk.Timestamp(),
0, // pChainHeight
proVM.ctx.StakingCertLeaf,
proVM.stakingCertLeaf,
coreBlk.Bytes(),
proVM.ctx.ChainID,
proVM.ctx.StakingLeafSigner,
proVM.stakingLeafSigner,
)
if err != nil {
t.Fatalf("unexpectedly could not build block due to %s", err)
Expand Down Expand Up @@ -799,10 +799,10 @@ func TestBlockVerify_ForkBlockIsOracleBlockButChildrenAreSigned(t *testing.T) {
firstBlock.ID(), // refer unknown parent
firstBlock.Timestamp(),
0, // pChainHeight,
proVM.ctx.StakingCertLeaf,
proVM.stakingCertLeaf,
coreBlk.opts[0].Bytes(),
proVM.ctx.ChainID,
proVM.ctx.StakingLeafSigner,
proVM.stakingLeafSigner,
)
if err != nil {
t.Fatal("could not build stateless block")
Expand Down
35 changes: 20 additions & 15 deletions vms/proposervm/state_syncable_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,17 @@ func helperBuildStateSyncTestObjects(t *testing.T) (*fullVM, *VM) {
dbManager := manager.NewMemDB(version.Semantic1_0_0)
dbManager = dbManager.NewPrefixDBManager([]byte{})

vm := New(innerVM, time.Time{}, 0, DefaultMinBlockDelay)
vm := New(
innerVM,
time.Time{},
0,
DefaultMinBlockDelay,
pTestCert.PrivateKey.(crypto.Signer),
pTestCert.Leaf,
)

ctx := snow.DefaultContextTest()
ctx.NodeID = ids.NodeIDFromCert(pTestCert.Leaf)
ctx.StakingCertLeaf = pTestCert.Leaf
ctx.StakingLeafSigner = pTestCert.PrivateKey.(crypto.Signer)

err := vm.Initialize(
context.Background(),
Expand Down Expand Up @@ -185,10 +190,10 @@ func TestStateSyncGetOngoingSyncStateSummary(t *testing.T) {
vm.preferred,
innerBlk.Timestamp(),
100, // pChainHeight,
vm.ctx.StakingCertLeaf,
vm.stakingCertLeaf,
innerBlk.Bytes(),
vm.ctx.ChainID,
vm.ctx.StakingLeafSigner,
vm.stakingLeafSigner,
)
require.NoError(err)
proBlk := &postForkBlock{
Expand Down Expand Up @@ -267,10 +272,10 @@ func TestStateSyncGetLastStateSummary(t *testing.T) {
vm.preferred,
innerBlk.Timestamp(),
100, // pChainHeight,
vm.ctx.StakingCertLeaf,
vm.stakingCertLeaf,
innerBlk.Bytes(),
vm.ctx.ChainID,
vm.ctx.StakingLeafSigner,
vm.stakingLeafSigner,
)
require.NoError(err)
proBlk := &postForkBlock{
Expand Down Expand Up @@ -352,10 +357,10 @@ func TestStateSyncGetStateSummary(t *testing.T) {
vm.preferred,
innerBlk.Timestamp(),
100, // pChainHeight,
vm.ctx.StakingCertLeaf,
vm.stakingCertLeaf,
innerBlk.Bytes(),
vm.ctx.ChainID,
vm.ctx.StakingLeafSigner,
vm.stakingLeafSigner,
)
require.NoError(err)
proBlk := &postForkBlock{
Expand Down Expand Up @@ -422,10 +427,10 @@ func TestParseStateSummary(t *testing.T) {
vm.preferred,
innerBlk.Timestamp(),
100, // pChainHeight,
vm.ctx.StakingCertLeaf,
vm.stakingCertLeaf,
innerBlk.Bytes(),
vm.ctx.ChainID,
vm.ctx.StakingLeafSigner,
vm.stakingLeafSigner,
)
require.NoError(err)
proBlk := &postForkBlock{
Expand Down Expand Up @@ -482,10 +487,10 @@ func TestStateSummaryAccept(t *testing.T) {
vm.preferred,
innerBlk.Timestamp(),
100, // pChainHeight,
vm.ctx.StakingCertLeaf,
vm.stakingCertLeaf,
innerBlk.Bytes(),
vm.ctx.ChainID,
vm.ctx.StakingLeafSigner,
vm.stakingLeafSigner,
)
require.NoError(err)
proBlk := &postForkBlock{
Expand Down Expand Up @@ -556,10 +561,10 @@ func TestStateSummaryAcceptOlderBlock(t *testing.T) {
vm.preferred,
innerBlk.Timestamp(),
100, // pChainHeight,
vm.ctx.StakingCertLeaf,
vm.stakingCertLeaf,
innerBlk.Bytes(),
vm.ctx.ChainID,
vm.ctx.StakingLeafSigner,
vm.stakingLeafSigner,
)
require.NoError(err)
proBlk := &postForkBlock{
Expand Down
Loading

0 comments on commit e38a148

Please sign in to comment.