Skip to content

Commit

Permalink
Merge branch 'master' into INFRA-3587-packer
Browse files Browse the repository at this point in the history
  • Loading branch information
yevhenvolchenko authored Mar 8, 2024
2 parents 20d019e + a593cc4 commit 77f99d9
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 158 deletions.
10 changes: 1 addition & 9 deletions network/peer/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,22 +716,14 @@ func (p *peer) shouldDisconnect() bool {
return false
}

postDurango := p.Clock.Time().After(version.GetDurangoTime(constants.MainnetID))
if postDurango && p.ip.BLSSignature == nil {
if p.ip.BLSSignature == nil {
p.Log.Debug("disconnecting from peer",
zap.String("reason", "missing BLS signature"),
zap.Stringer("nodeID", p.id),
)
return true
}

// If Durango hasn't activated on mainnet yet, we don't require BLS
// signatures to be provided. However, if they are provided, verify that
// they are correct.
if p.ip.BLSSignature == nil {
return false
}

validSignature := bls.VerifyProofOfPossession(
vdr.PublicKey,
p.ip.BLSSignature,
Expand Down
91 changes: 3 additions & 88 deletions network/peer/peer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/ava-labs/avalanchego/utils/math/meter"
"github.com/ava-labs/avalanchego/utils/resource"
"github.com/ava-labs/avalanchego/utils/set"
"github.com/ava-labs/avalanchego/utils/timer/mockable"
"github.com/ava-labs/avalanchego/version"
)

Expand Down Expand Up @@ -591,14 +590,9 @@ func TestShouldDisconnect(t *testing.T) {
expectedShouldDisconnect: false,
},
{
name: "past durango without a signature",
name: "peer without signature",
initialPeer: &peer{
Config: &Config{
Clock: func() mockable.Clock {
clk := mockable.Clock{}
clk.Set(mockable.MaxTime)
return clk
}(),
Log: logging.NoLog{},
VersionCompatibility: version.GetCompatibility(constants.UnitTestID),
Validators: func() validators.Manager {
Expand All @@ -619,11 +613,6 @@ func TestShouldDisconnect(t *testing.T) {
},
expectedPeer: &peer{
Config: &Config{
Clock: func() mockable.Clock {
clk := mockable.Clock{}
clk.Set(mockable.MaxTime)
return clk
}(),
Log: logging.NoLog{},
VersionCompatibility: version.GetCompatibility(constants.UnitTestID),
Validators: func() validators.Manager {
Expand All @@ -645,68 +634,9 @@ func TestShouldDisconnect(t *testing.T) {
expectedShouldDisconnect: true,
},
{
name: "pre durango without a signature",
name: "peer with invalid signature",
initialPeer: &peer{
Config: &Config{
Clock: func() mockable.Clock {
clk := mockable.Clock{}
clk.Set(time.Time{})
return clk
}(),
Log: logging.NoLog{},
VersionCompatibility: version.GetCompatibility(constants.UnitTestID),
Validators: func() validators.Manager {
vdrs := validators.NewManager()
require.NoError(t, vdrs.AddStaker(
constants.PrimaryNetworkID,
peerID,
bls.PublicFromSecretKey(blsKey),
txID,
1,
))
return vdrs
}(),
},
id: peerID,
version: version.CurrentApp,
ip: &SignedIP{},
},
expectedPeer: &peer{
Config: &Config{
Clock: func() mockable.Clock {
clk := mockable.Clock{}
clk.Set(time.Time{})
return clk
}(),
Log: logging.NoLog{},
VersionCompatibility: version.GetCompatibility(constants.UnitTestID),
Validators: func() validators.Manager {
vdrs := validators.NewManager()
require.NoError(t, vdrs.AddStaker(
constants.PrimaryNetworkID,
peerID,
bls.PublicFromSecretKey(blsKey),
txID,
1,
))
return vdrs
}(),
},
id: peerID,
version: version.CurrentApp,
ip: &SignedIP{},
},
expectedShouldDisconnect: false,
},
{
name: "pre durango with an invalid signature",
initialPeer: &peer{
Config: &Config{
Clock: func() mockable.Clock {
clk := mockable.Clock{}
clk.Set(time.Time{})
return clk
}(),
Log: logging.NoLog{},
VersionCompatibility: version.GetCompatibility(constants.UnitTestID),
Validators: func() validators.Manager {
Expand All @@ -729,11 +659,6 @@ func TestShouldDisconnect(t *testing.T) {
},
expectedPeer: &peer{
Config: &Config{
Clock: func() mockable.Clock {
clk := mockable.Clock{}
clk.Set(time.Time{})
return clk
}(),
Log: logging.NoLog{},
VersionCompatibility: version.GetCompatibility(constants.UnitTestID),
Validators: func() validators.Manager {
Expand All @@ -757,14 +682,9 @@ func TestShouldDisconnect(t *testing.T) {
expectedShouldDisconnect: true,
},
{
name: "pre durango with a valid signature",
name: "peer with valid signature",
initialPeer: &peer{
Config: &Config{
Clock: func() mockable.Clock {
clk := mockable.Clock{}
clk.Set(time.Time{})
return clk
}(),
Log: logging.NoLog{},
VersionCompatibility: version.GetCompatibility(constants.UnitTestID),
Validators: func() validators.Manager {
Expand All @@ -787,11 +707,6 @@ func TestShouldDisconnect(t *testing.T) {
},
expectedPeer: &peer{
Config: &Config{
Clock: func() mockable.Clock {
clk := mockable.Clock{}
clk.Set(time.Time{})
return clk
}(),
Log: logging.NoLog{},
VersionCompatibility: version.GetCompatibility(constants.UnitTestID),
Validators: func() validators.Manager {
Expand Down
4 changes: 1 addition & 3 deletions snow/networking/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,9 +716,7 @@ func (h *handler) handleSyncMsg(ctx context.Context, msg Message) error {
zap.String("field", "PreferredIDAtHeight"),
zap.Error(err),
)
// TODO: Require this field to be populated correctly after v1.11.x
// is activated.
preferredIDAtHeight = preferredID
return engine.QueryFailed(ctx, nodeID, msg.RequestId)
}

acceptedID, err := ids.ToID(msg.AcceptedId)
Expand Down
43 changes: 13 additions & 30 deletions vms/platformvm/block/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,19 @@ func buildBlock(
forceAdvanceTime bool,
parentState state.Chain,
) (block.Block, error) {
blockTxs, err := packBlockTxs(
parentID,
parentState,
builder.Mempool,
builder.txExecutorBackend,
builder.blkManager,
timestamp,
targetBlockSize,
)
if err != nil {
return nil, fmt.Errorf("failed to pack block txs: %w", err)
}

// Try rewarding stakers whose staking period ends at the new chain time.
// This is done first to prioritize advancing the timestamp as quickly as
// possible.
Expand All @@ -276,23 +289,6 @@ func buildBlock(
return nil, fmt.Errorf("could not build tx to reward staker: %w", err)
}

var blockTxs []*txs.Tx
// TODO: Cleanup post-Durango
if builder.txExecutorBackend.Config.IsDurangoActivated(timestamp) {
blockTxs, err = packBlockTxs(
parentID,
parentState,
builder.Mempool,
builder.txExecutorBackend,
builder.blkManager,
timestamp,
targetBlockSize,
)
if err != nil {
return nil, fmt.Errorf("failed to pack block txs: %w", err)
}
}

return block.NewBanffProposalBlock(
timestamp,
parentID,
Expand All @@ -302,19 +298,6 @@ func buildBlock(
)
}

blockTxs, err := packBlockTxs(
parentID,
parentState,
builder.Mempool,
builder.txExecutorBackend,
builder.blkManager,
timestamp,
targetBlockSize,
)
if err != nil {
return nil, fmt.Errorf("failed to pack block txs: %w", err)
}

// If there is no reason to build a block, don't.
if len(blockTxs) == 0 && !forceAdvanceTime {
builder.txExecutorBackend.Ctx.Log.Debug("no pending txs to issue into a block")
Expand Down
17 changes: 0 additions & 17 deletions vms/platformvm/block/executor/proposal_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,23 +334,6 @@ func TestBanffProposalBlockTimeVerification(t *testing.T) {
require.ErrorIs(err, executor.ErrAdvanceTimeTxIssuedAfterBanff)
}

{
// include too many transactions
statelessProposalBlock, err := block.NewBanffProposalBlock(
nextStakerTime,
parentID,
banffParentBlk.Height()+1,
blkTx,
[]*txs.Tx{},
)
require.NoError(err)

statelessProposalBlock.Transactions = []*txs.Tx{blkTx}
block := env.blkManager.NewBlock(statelessProposalBlock)
err = block.Verify(context.Background())
require.ErrorIs(err, errBanffProposalBlockWithMultipleTransactions)
}

{
// valid
statelessProposalBlock, err := block.NewBanffProposalBlock(
Expand Down
17 changes: 6 additions & 11 deletions vms/platformvm/block/executor/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ var (

ErrConflictingBlockTxs = errors.New("block contains conflicting transactions")

errApricotBlockIssuedAfterFork = errors.New("apricot block issued after fork")
errBanffProposalBlockWithMultipleTransactions = errors.New("BanffProposalBlock contains multiple transactions")
errBanffStandardBlockWithoutChanges = errors.New("BanffStandardBlock performs no state changes")
errIncorrectBlockHeight = errors.New("incorrect block height")
errChildBlockEarlierThanParent = errors.New("proposed timestamp before current chain time")
errOptionBlockTimestampNotMatchingParent = errors.New("option block proposed timestamp not matching parent block one")
errApricotBlockIssuedAfterFork = errors.New("apricot block issued after fork")
errBanffStandardBlockWithoutChanges = errors.New("BanffStandardBlock performs no state changes")
errIncorrectBlockHeight = errors.New("incorrect block height")
errChildBlockEarlierThanParent = errors.New("proposed timestamp before current chain time")
errOptionBlockTimestampNotMatchingParent = errors.New("option block proposed timestamp not matching parent block one")
)

// verifier handles the logic for verifying a block.
Expand All @@ -51,11 +50,6 @@ func (v *verifier) BanffCommitBlock(b *block.BanffCommitBlock) error {
}

func (v *verifier) BanffProposalBlock(b *block.BanffProposalBlock) error {
nextChainTime := b.Timestamp()
if !v.txExecutorBackend.Config.IsDurangoActivated(nextChainTime) && len(b.Transactions) != 0 {
return errBanffProposalBlockWithMultipleTransactions
}

if err := v.banffNonOptionBlock(b); err != nil {
return err
}
Expand All @@ -67,6 +61,7 @@ func (v *verifier) BanffProposalBlock(b *block.BanffProposalBlock) error {
}

// Advance the time to [nextChainTime].
nextChainTime := b.Timestamp()
if _, err := executor.AdvanceTimeTo(v.txExecutorBackend, onDecisionState, nextChainTime); err != nil {
return err
}
Expand Down

0 comments on commit 77f99d9

Please sign in to comment.