Skip to content

Commit

Permalink
Remove block.Status (#3158)
Browse files Browse the repository at this point in the history
Co-authored-by: Aaron Buchwald <[email protected]>
  • Loading branch information
StephenButtolph and aaronbuchwald authored Jul 16, 2024
1 parent f621356 commit abb1a9a
Show file tree
Hide file tree
Showing 53 changed files with 1,262 additions and 1,953 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/DataDog/zstd v1.5.2
github.com/NYTimes/gziphandler v1.1.1
github.com/antithesishq/antithesis-sdk-go v0.3.8
github.com/ava-labs/coreth v0.13.6-rc.1.0.20240702201359-ba2ce5367874
github.com/ava-labs/coreth v0.13.7-remove-status
github.com/ava-labs/ledger-avalanche/go v0.0.0-20240610153809-9c955cc90a95
github.com/btcsuite/btcd/btcutil v1.1.3
github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax
github.com/antithesishq/antithesis-sdk-go v0.3.8 h1:OvGoHxIcOXFJLyn9IJQ5DzByZ3YVAWNBc394ObzDRb8=
github.com/antithesishq/antithesis-sdk-go v0.3.8/go.mod h1:IUpT2DPAKh6i/YhSbt6Gl3v2yvUZjmKncl7U91fup7E=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/ava-labs/coreth v0.13.6-rc.1.0.20240702201359-ba2ce5367874 h1:aTDg0jvO07EvUvBYebmLO25bffe1DAaZZPPL0ooGhIA=
github.com/ava-labs/coreth v0.13.6-rc.1.0.20240702201359-ba2ce5367874/go.mod h1:VhNDxZBsqZQQaUTmIkzdyY8UicIsoTDXlRmPaPL9lkA=
github.com/ava-labs/coreth v0.13.7-remove-status h1:NVHOcHcHpgiVbGYQ1TcnnAbf16tONluvVnYt/Gi+bOA=
github.com/ava-labs/coreth v0.13.7-remove-status/go.mod h1:lTa5PYte0AXBtUK866iQrURSuJLprubKjztbDrTWSrQ=
github.com/ava-labs/ledger-avalanche/go v0.0.0-20240610153809-9c955cc90a95 h1:dOVbtdnZL++pENdTCNZ1nu41eYDQkTML4sWebDnnq8c=
github.com/ava-labs/ledger-avalanche/go v0.0.0-20240610153809-9c955cc90a95/go.mod h1:pJxaT9bUgeRNVmNRgtCHb7sFDIRKy7CzTQVi8gGNT6g=
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
Expand Down
1,078 changes: 498 additions & 580 deletions proto/pb/vm/vm.pb.go

Large diffs are not rendered by default.

9 changes: 0 additions & 9 deletions proto/vm/vm.proto
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,6 @@ enum State {
STATE_NORMAL_OP = 3;
}

enum Status {
STATUS_UNSPECIFIED = 0;
STATUS_PROCESSING = 1;
STATUS_REJECTED = 2;
STATUS_ACCEPTED = 3;
}

enum Error {
// ERROR_UNSPECIFIED is used to indicate that no error occurred.
ERROR_UNSPECIFIED = 0;
Expand Down Expand Up @@ -177,7 +170,6 @@ message ParseBlockRequest {
message ParseBlockResponse {
bytes id = 1;
bytes parent_id = 2;
Status status = 3;
uint64 height = 4;
google.protobuf.Timestamp timestamp = 5;
bool verify_with_context = 6;
Expand All @@ -190,7 +182,6 @@ message GetBlockRequest {
message GetBlockResponse {
bytes parent_id = 1;
bytes bytes = 2;
Status status = 3;
uint64 height = 4;
google.protobuf.Timestamp timestamp = 5;
// used to propagate database.ErrNotFound through RPC
Expand Down
4 changes: 2 additions & 2 deletions snow/consensus/snowman/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"time"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/choices"
"github.com/ava-labs/avalanchego/snow"
)

// Block is a possible decision that dictates the next canonical block.
Expand All @@ -22,7 +22,7 @@ import (
// If the status of the block is Accepted or Rejected; Parent, Verify, Accept,
// and Reject will never be called.
type Block interface {
choices.Decidable
snow.Decidable

// Parent returns the ID of this block's parent.
Parent() ids.ID
Expand Down
101 changes: 50 additions & 51 deletions snow/consensus/snowman/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"gonum.org/v1/gonum/mathext/prng"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/choices"
"github.com/ava-labs/avalanchego/snow/consensus/snowball"
"github.com/ava-labs/avalanchego/snow/consensus/snowman/snowmantest"
"github.com/ava-labs/avalanchego/snow/snowtest"
Expand Down Expand Up @@ -251,9 +250,9 @@ func AddOnUnknownParentTest(t *testing.T, factory Factory) {
))

block := &snowmantest.Block{
TestDecidable: choices.TestDecidable{
IDV: ids.GenerateTestID(),
StatusV: choices.Processing,
Decidable: snowtest.Decidable{
IDV: ids.GenerateTestID(),
Status: snowtest.Undecided,
},
ParentV: ids.GenerateTestID(),
HeightV: snowmantest.GenesisHeight + 2,
Expand Down Expand Up @@ -289,7 +288,7 @@ func StatusOrProcessingPreviouslyAcceptedTest(t *testing.T, factory Factory) {
snowmantest.GenesisTimestamp,
))

require.Equal(choices.Accepted, snowmantest.Genesis.Status())
require.Equal(snowtest.Accepted, snowmantest.Genesis.Status)
require.False(sm.Processing(snowmantest.Genesis.ID()))
require.True(sm.IsPreferred(snowmantest.Genesis.ID()))

Expand Down Expand Up @@ -326,7 +325,7 @@ func StatusOrProcessingPreviouslyRejectedTest(t *testing.T, factory Factory) {
block := snowmantest.BuildChild(snowmantest.Genesis)
require.NoError(block.Reject(context.Background()))

require.Equal(choices.Rejected, block.Status())
require.Equal(snowtest.Rejected, block.Status)
require.False(sm.Processing(block.ID()))
require.False(sm.IsPreferred(block.ID()))

Expand Down Expand Up @@ -361,7 +360,7 @@ func StatusOrProcessingUnissuedTest(t *testing.T, factory Factory) {

block := snowmantest.BuildChild(snowmantest.Genesis)

require.Equal(choices.Processing, block.Status())
require.Equal(snowtest.Undecided, block.Status)
require.False(sm.Processing(block.ID()))
require.False(sm.IsPreferred(block.ID()))

Expand Down Expand Up @@ -397,7 +396,7 @@ func StatusOrProcessingIssuedTest(t *testing.T, factory Factory) {
block := snowmantest.BuildChild(snowmantest.Genesis)

require.NoError(sm.Add(block))
require.Equal(choices.Processing, block.Status())
require.Equal(snowtest.Undecided, block.Status)
require.True(sm.Processing(block.ID()))
require.True(sm.IsPreferred(block.ID()))

Expand Down Expand Up @@ -439,12 +438,12 @@ func RecordPollAcceptSingleBlockTest(t *testing.T, factory Factory) {
require.NoError(sm.RecordPoll(context.Background(), votes))
require.Equal(block.ID(), sm.Preference())
require.Equal(1, sm.NumProcessing())
require.Equal(choices.Processing, block.Status())
require.Equal(snowtest.Undecided, block.Status)

require.NoError(sm.RecordPoll(context.Background(), votes))
require.Equal(block.ID(), sm.Preference())
require.Zero(sm.NumProcessing())
require.Equal(choices.Accepted, block.Status())
require.Equal(snowtest.Accepted, block.Status)
}

func RecordPollAcceptAndRejectTest(t *testing.T, factory Factory) {
Expand Down Expand Up @@ -483,14 +482,14 @@ func RecordPollAcceptAndRejectTest(t *testing.T, factory Factory) {
require.NoError(sm.RecordPoll(context.Background(), votes))
require.Equal(firstBlock.ID(), sm.Preference())
require.Equal(2, sm.NumProcessing())
require.Equal(choices.Processing, firstBlock.Status())
require.Equal(choices.Processing, secondBlock.Status())
require.Equal(snowtest.Undecided, firstBlock.Status)
require.Equal(snowtest.Undecided, secondBlock.Status)

require.NoError(sm.RecordPoll(context.Background(), votes))
require.Equal(firstBlock.ID(), sm.Preference())
require.Zero(sm.NumProcessing())
require.Equal(choices.Accepted, firstBlock.Status())
require.Equal(choices.Rejected, secondBlock.Status())
require.Equal(snowtest.Accepted, firstBlock.Status)
require.Equal(snowtest.Rejected, secondBlock.Status)
}

func RecordPollSplitVoteNoChangeTest(t *testing.T, factory Factory) {
Expand Down Expand Up @@ -628,9 +627,9 @@ func RecordPollRejectTransitivelyTest(t *testing.T, factory Factory) {

require.Zero(sm.NumProcessing())
require.Equal(block0.ID(), sm.Preference())
require.Equal(choices.Accepted, block0.Status())
require.Equal(choices.Rejected, block1.Status())
require.Equal(choices.Rejected, block2.Status())
require.Equal(snowtest.Accepted, block0.Status)
require.Equal(snowtest.Rejected, block1.Status)
require.Equal(snowtest.Rejected, block2.Status)
}

func RecordPollTransitivelyResetConfidenceTest(t *testing.T, factory Factory) {
Expand Down Expand Up @@ -697,10 +696,10 @@ func RecordPollTransitivelyResetConfidenceTest(t *testing.T, factory Factory) {
require.NoError(sm.RecordPoll(context.Background(), votesFor3))
require.Zero(sm.NumProcessing())
require.Equal(block3.ID(), sm.Preference())
require.Equal(choices.Rejected, block0.Status())
require.Equal(choices.Accepted, block1.Status())
require.Equal(choices.Rejected, block2.Status())
require.Equal(choices.Accepted, block3.Status())
require.Equal(snowtest.Rejected, block0.Status)
require.Equal(snowtest.Accepted, block1.Status)
require.Equal(snowtest.Rejected, block2.Status)
require.Equal(snowtest.Accepted, block3.Status)
}

func RecordPollInvalidVoteTest(t *testing.T, factory Factory) {
Expand Down Expand Up @@ -803,11 +802,11 @@ func RecordPollTransitiveVotingTest(t *testing.T, factory Factory) {

require.Equal(4, sm.NumProcessing())
require.Equal(block2.ID(), sm.Preference())
require.Equal(choices.Accepted, block0.Status())
require.Equal(choices.Processing, block1.Status())
require.Equal(choices.Processing, block2.Status())
require.Equal(choices.Processing, block3.Status())
require.Equal(choices.Processing, block4.Status())
require.Equal(snowtest.Accepted, block0.Status)
require.Equal(snowtest.Undecided, block1.Status)
require.Equal(snowtest.Undecided, block2.Status)
require.Equal(snowtest.Undecided, block3.Status)
require.Equal(snowtest.Undecided, block4.Status)

dep2_2_2 := bag.Of(block2.ID(), block2.ID(), block2.ID())
require.NoError(sm.RecordPoll(context.Background(), dep2_2_2))
Expand All @@ -818,11 +817,11 @@ func RecordPollTransitiveVotingTest(t *testing.T, factory Factory) {

require.Zero(sm.NumProcessing())
require.Equal(block2.ID(), sm.Preference())
require.Equal(choices.Accepted, block0.Status())
require.Equal(choices.Accepted, block1.Status())
require.Equal(choices.Accepted, block2.Status())
require.Equal(choices.Rejected, block3.Status())
require.Equal(choices.Rejected, block4.Status())
require.Equal(snowtest.Accepted, block0.Status)
require.Equal(snowtest.Accepted, block1.Status)
require.Equal(snowtest.Accepted, block2.Status)
require.Equal(snowtest.Rejected, block3.Status)
require.Equal(snowtest.Rejected, block4.Status)
}

func RecordPollDivergedVotingWithNoConflictingBitTest(t *testing.T, factory Factory) {
Expand Down Expand Up @@ -850,25 +849,25 @@ func RecordPollDivergedVotingWithNoConflictingBitTest(t *testing.T, factory Fact
))

block0 := &snowmantest.Block{
TestDecidable: choices.TestDecidable{
IDV: ids.ID{0x06}, // 0110
StatusV: choices.Processing,
Decidable: snowtest.Decidable{
IDV: ids.ID{0x06}, // 0110
Status: snowtest.Undecided,
},
ParentV: snowmantest.GenesisID,
HeightV: snowmantest.GenesisHeight + 1,
}
block1 := &snowmantest.Block{
TestDecidable: choices.TestDecidable{
IDV: ids.ID{0x08}, // 0001
StatusV: choices.Processing,
Decidable: snowtest.Decidable{
IDV: ids.ID{0x08}, // 0001
Status: snowtest.Undecided,
},
ParentV: snowmantest.GenesisID,
HeightV: snowmantest.GenesisHeight + 1,
}
block2 := &snowmantest.Block{
TestDecidable: choices.TestDecidable{
IDV: ids.ID{0x01}, // 1000
StatusV: choices.Processing,
Decidable: snowtest.Decidable{
IDV: ids.ID{0x01}, // 1000
Status: snowtest.Undecided,
},
ParentV: snowmantest.GenesisID,
HeightV: snowmantest.GenesisHeight + 1,
Expand Down Expand Up @@ -896,10 +895,10 @@ func RecordPollDivergedVotingWithNoConflictingBitTest(t *testing.T, factory Fact
require.NoError(sm.Add(block3))

require.Equal(block0.ID(), sm.Preference())
require.Equal(choices.Processing, block0.Status(), "should not be decided yet")
require.Equal(choices.Processing, block1.Status(), "should not be decided yet")
require.Equal(choices.Processing, block2.Status(), "should not be decided yet")
require.Equal(choices.Processing, block3.Status(), "should not be decided yet")
require.Equal(snowtest.Undecided, block0.Status, "should not be decided yet")
require.Equal(snowtest.Undecided, block1.Status, "should not be decided yet")
require.Equal(snowtest.Undecided, block2.Status, "should not be decided yet")
require.Equal(snowtest.Undecided, block3.Status, "should not be decided yet")

// Current graph structure:
// G
Expand All @@ -921,10 +920,10 @@ func RecordPollDivergedVotingWithNoConflictingBitTest(t *testing.T, factory Fact
require.NoError(sm.RecordPoll(context.Background(), votes3))

require.Equal(4, sm.NumProcessing())
require.Equal(choices.Processing, block0.Status())
require.Equal(choices.Processing, block1.Status())
require.Equal(choices.Processing, block2.Status())
require.Equal(choices.Processing, block3.Status())
require.Equal(snowtest.Undecided, block0.Status)
require.Equal(snowtest.Undecided, block1.Status)
require.Equal(snowtest.Undecided, block2.Status)
require.Equal(snowtest.Undecided, block3.Status)
}

func RecordPollChangePreferredChainTest(t *testing.T, factory Factory) {
Expand Down Expand Up @@ -1462,7 +1461,7 @@ func RecordPollRegressionCalculateInDegreeIndegreeCalculation(t *testing.T, fact
votes.AddCount(blk2.ID(), 1)
votes.AddCount(blk3.ID(), 2)
require.NoError(sm.RecordPoll(context.Background(), votes))
require.Equal(choices.Accepted, blk1.Status())
require.Equal(choices.Accepted, blk2.Status())
require.Equal(choices.Accepted, blk3.Status())
require.Equal(snowtest.Accepted, blk1.Status)
require.Equal(snowtest.Accepted, blk2.Status)
require.Equal(snowtest.Accepted, blk3.Status)
}
5 changes: 2 additions & 3 deletions snow/consensus/snowman/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"go.uber.org/zap"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/choices"
"github.com/ava-labs/avalanchego/utils/linked"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/metric"
Expand Down Expand Up @@ -184,7 +183,7 @@ func (m *metrics) Accepted(
if !ok {
m.log.Error("unable to measure latency",
zap.Stringer("blkID", blkID),
zap.Stringer("status", choices.Accepted),
zap.String("status", "accepted"),
)
return
}
Expand All @@ -210,7 +209,7 @@ func (m *metrics) Rejected(blkID ids.ID, pollNumber uint64, blockSize int) {
if !ok {
m.log.Error("unable to measure latency",
zap.Stringer("blkID", blkID),
zap.Stringer("status", choices.Rejected),
zap.String("status", "rejected"),
)
return
}
Expand Down
19 changes: 9 additions & 10 deletions snow/consensus/snowman/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"testing"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/choices"
"github.com/ava-labs/avalanchego/snow/consensus/snowball"
"github.com/ava-labs/avalanchego/snow/consensus/snowman/snowmantest"
"github.com/ava-labs/avalanchego/snow/snowtest"
Expand All @@ -28,9 +27,9 @@ func NewNetwork(params snowball.Parameters, numColors int, rngSource sampler.Sou
n := &Network{
params: params,
colors: []*snowmantest.Block{{
TestDecidable: choices.TestDecidable{
IDV: ids.Empty.Prefix(rngSource.Uint64()),
StatusV: choices.Processing,
Decidable: snowtest.Decidable{
IDV: ids.Empty.Prefix(rngSource.Uint64()),
Status: snowtest.Undecided,
},
ParentV: snowmantest.GenesisID,
HeightV: snowmantest.GenesisHeight + 1,
Expand All @@ -44,9 +43,9 @@ func NewNetwork(params snowball.Parameters, numColors int, rngSource sampler.Sou
dependencyInd, _ := s.Next()
dependency := n.colors[dependencyInd]
n.colors = append(n.colors, &snowmantest.Block{
TestDecidable: choices.TestDecidable{
IDV: ids.Empty.Prefix(rngSource.Uint64()),
StatusV: choices.Processing,
Decidable: snowtest.Decidable{
IDV: ids.Empty.Prefix(rngSource.Uint64()),
Status: snowtest.Undecided,
},
ParentV: dependency.IDV,
HeightV: dependency.HeightV + 1,
Expand Down Expand Up @@ -82,9 +81,9 @@ func (n *Network) AddNode(t testing.TB, sm Consensus) error {
myDep = blk.Parent()
}
myBlock := &snowmantest.Block{
TestDecidable: choices.TestDecidable{
IDV: blk.ID(),
StatusV: blk.Status(),
Decidable: snowtest.Decidable{
IDV: blk.ID(),
Status: blk.Status,
},
ParentV: myDep,
HeightV: blk.Height(),
Expand Down
Loading

0 comments on commit abb1a9a

Please sign in to comment.