Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove lists from Chits messages #1412

Merged
merged 29 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5a1bdb3
If the network is not fuji or mainnet linearize on init
StephenButtolph Mar 20, 2023
f6d6d18
Loop until stop vertex is accepted
StephenButtolph Mar 20, 2023
3c96f9b
If the stop vertex is accepted, transition to snowman bootstrapping
StephenButtolph Mar 20, 2023
9f1f252
merged
StephenButtolph Mar 20, 2023
af9460a
merged
StephenButtolph Apr 13, 2023
75f42a5
wip removing avalanche consensus engine
StephenButtolph Apr 13, 2023
1be3d27
Use require in Avalanche bootstrapping tests
StephenButtolph Apr 13, 2023
9614cec
Merge branch 'cleanup-avalanche-bootstrap-tests' into linearize-on-start
StephenButtolph Apr 13, 2023
853a70c
merged
StephenButtolph Apr 13, 2023
dd8c14f
remove bootstrapping tests from the consensus engine
StephenButtolph Apr 13, 2023
fff4c15
lint
StephenButtolph Apr 13, 2023
83cb219
wip fix tests
StephenButtolph Apr 14, 2023
c56755a
fix tests
StephenButtolph Apr 14, 2023
395e510
Merge branch 'dev' into cleanup-avalanche-bootstrap-tests
StephenButtolph Apr 14, 2023
1d8904b
Merge branch 'cleanup-avalanche-bootstrap-tests' into linearize-on-start
StephenButtolph Apr 14, 2023
50e9ebd
Update metrics
StephenButtolph Apr 14, 2023
ad9b139
Merge branch 'linearize-on-start' of github.com:ava-labs/avalanchego …
StephenButtolph Apr 14, 2023
708b260
remove whitelist vtx tests
StephenButtolph Apr 14, 2023
caa60ba
Remove avalanche consensus
StephenButtolph Apr 15, 2023
5b8ae87
Remove whitelist interface
StephenButtolph Apr 15, 2023
798d62b
Remove more dead code
StephenButtolph Apr 15, 2023
d56f8da
deadcode
StephenButtolph Apr 15, 2023
b113a2b
merged
StephenButtolph Apr 24, 2023
87d0f99
merged
StephenButtolph Apr 24, 2023
06ee7bf
Remove lists from Chits messages
StephenButtolph Apr 24, 2023
869a04a
merged
StephenButtolph Apr 25, 2023
0abb509
Merge branch 'remove-avalanche-consensus' into simplify-chits-message
StephenButtolph Apr 25, 2023
4991f15
merged
StephenButtolph Jun 1, 2023
c824df4
remove old comment
StephenButtolph Jun 1, 2023
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
Prev Previous commit
Next Next commit
Remove more dead code
  • Loading branch information
StephenButtolph committed Apr 15, 2023
commit 798d62b7bbd5e8aa0b7237563fa009be82182266
3 changes: 0 additions & 3 deletions snow/consensus/avalanche/vertex.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ import (
type Vertex interface {
choices.Decidable

// Vertex verification should be performed before issuance.
Verify(context.Context) error

// Returns the vertices this vertex depends on
Parents() ([]Vertex, error)

Expand Down
3 changes: 0 additions & 3 deletions snow/engine/avalanche/bootstrap/bootstrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,6 @@ func (b *bootstrapper) Start(ctx context.Context, startReqID uint32) error {
if err != nil {
return fmt.Errorf("failed to create stop vertex: %w", err)
}
if err := stopVertex.Verify(ctx); err != nil {
return fmt.Errorf("failed to verify stop vertex: %w", err)
}
if err := stopVertex.Accept(ctx); err != nil {
return fmt.Errorf("failed to accept stop vertex: %w", err)
}
Expand Down
43 changes: 4 additions & 39 deletions snow/engine/avalanche/state/serializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/choices"
"github.com/ava-labs/avalanchego/snow/consensus/avalanche"
"github.com/ava-labs/avalanchego/snow/consensus/snowstorm"
"github.com/ava-labs/avalanchego/snow/engine/avalanche/vertex"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/math"
Expand Down Expand Up @@ -76,26 +75,9 @@ func (s *Serializer) ParseVtx(ctx context.Context, b []byte) (avalanche.Vertex,
return newUniqueVertex(ctx, s, b)
}

func (s *Serializer) BuildVtx(
ctx context.Context,
parentIDs []ids.ID,
txs []snowstorm.Tx,
) (avalanche.Vertex, error) {
return s.buildVtx(ctx, parentIDs, txs, false)
}

func (s *Serializer) BuildStopVtx(
ctx context.Context,
parentIDs []ids.ID,
) (avalanche.Vertex, error) {
return s.buildVtx(ctx, parentIDs, nil, true)
}

func (s *Serializer) buildVtx(
ctx context.Context,
parentIDs []ids.ID,
txs []snowstorm.Tx,
stopVtx bool,
) (avalanche.Vertex, error) {
height := uint64(0)
for _, parentID := range parentIDs {
Expand All @@ -111,28 +93,11 @@ func (s *Serializer) buildVtx(
height = math.Max(height, childHeight)
}

var (
vtx vertex.StatelessVertex
err error
vtx, err := vertex.BuildStopVertex(
s.ChainID,
height,
parentIDs,
)
if !stopVtx {
txBytes := make([][]byte, len(txs))
for i, tx := range txs {
txBytes[i] = tx.Bytes()
}
vtx, err = vertex.Build(
s.ChainID,
height,
parentIDs,
txBytes,
)
} else {
vtx, err = vertex.BuildStopVertex(
s.ChainID,
height,
parentIDs,
)
}
if err != nil {
return nil, err
}
Expand Down
146 changes: 0 additions & 146 deletions snow/engine/avalanche/state/unique_vertex.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ package state

import (
"context"
"errors"
"fmt"
"strings"
"time"

"github.com/ava-labs/avalanchego/cache"
"github.com/ava-labs/avalanchego/ids"
Expand All @@ -18,7 +16,6 @@ import (
"github.com/ava-labs/avalanchego/snow/engine/avalanche/vertex"
"github.com/ava-labs/avalanchego/utils/formatting"
"github.com/ava-labs/avalanchego/utils/hashing"
"github.com/ava-labs/avalanchego/utils/set"
)

var (
Expand All @@ -37,8 +34,6 @@ type uniqueVertex struct {

id ids.ID
v *vertexState
// default to "time.Now", used for testing
time func() time.Time
}

// newUniqueVertex returns a uniqueVertex instance from [b] by checking the cache
Expand Down Expand Up @@ -242,137 +237,6 @@ func (vtx *uniqueVertex) Parents() ([]avalanche.Vertex, error) {
return vtx.v.parents, nil
}

var (
errStopVertexNotAllowedTimestamp = errors.New("stop vertex not allowed timestamp")
errStopVertexAlreadyAccepted = errors.New("stop vertex already accepted")
errUnexpectedEdges = errors.New("unexpected edge, expected accepted frontier")
errUnexpectedDependencyStopVtx = errors.New("unexpected dependencies found in stop vertex transitive path")
)

// "uniqueVertex" itself implements "Verify" regardless of whether the underlying vertex
// is stop vertex or not. Called before issuing the vertex to the consensus.
// No vertex should ever be able to refer to a stop vertex in its transitive closure.
func (vtx *uniqueVertex) Verify(ctx context.Context) error {
// first verify the underlying stateless vertex
if err := vtx.v.vtx.Verify(); err != nil {
return err
}

whitelistVtx := vtx.v.vtx.StopVertex()
if whitelistVtx {
now := time.Now()
if vtx.time != nil {
now = vtx.time()
}
allowed := vtx.serializer.CortinaTime
if now.Before(allowed) {
return errStopVertexNotAllowedTimestamp
}
}

// MUST error if stop vertex has already been accepted (can't be accepted twice)
// regardless of whether the underlying vertex is stop vertex or not
stopVtxAccepted, err := vtx.serializer.StopVertexAccepted(ctx)
if err != nil {
return err
}
if stopVtxAccepted {
return errStopVertexAlreadyAccepted
}
if !whitelistVtx {
// below are stop vertex specific verifications
// no need to continue
return nil
}

// (accepted) (accepted)
// vtx_1 vtx_2
// [tx_a, tx_b] [tx_c, tx_d]
// ⬆ ⬉ ⬈ ⬆
// vtx_3 vtx_4
// [tx_e, tx_f] [tx_g, tx_h]
// ⬆
// stop_vertex_5
//
// [tx_a, tx_b] transitively referenced by "stop_vertex_5"
// has the dependent transactions [tx_e, tx_f]
// that are not transitively referenced by "stop_vertex_5"
// in case "tx_g" depends on "tx_e" that is not in vtx4.
// Thus "stop_vertex_5" is invalid!
//
// To make sure such transitive paths of the stop vertex reach all accepted frontier:
// 1. check the edge of the transitive paths refers to the accepted frontier
// 2. check dependencies of all txs must be subset of transitive paths
queue := []avalanche.Vertex{vtx}
visitedVtx := set.NewSet[ids.ID](0)

acceptedFrontier := set.NewSet[ids.ID](0)
transitivePaths := set.NewSet[ids.ID](0)
dependencies := set.NewSet[ids.ID](0)
for len(queue) > 0 { // perform BFS
cur := queue[0]
queue = queue[1:]

curID := cur.ID()
if cur.Status() == choices.Accepted {
// 1. check the edge of the transitive paths refers to the accepted frontier
acceptedFrontier.Add(curID)

// have reached the accepted frontier on the transitive closure
// no need to continue the search on this path
continue
}

if visitedVtx.Contains(curID) {
continue
}
visitedVtx.Add(curID)
transitivePaths.Add(curID)

txs, err := cur.Txs(ctx)
if err != nil {
return err
}
for _, tx := range txs {
transitivePaths.Add(tx.ID())
deps, err := tx.Dependencies()
if err != nil {
return err
}
for _, dep := range deps {
// only add non-accepted dependencies
if dep.Status() != choices.Accepted {
dependencies.Add(dep.ID())
}
}
}

parents, err := cur.Parents()
if err != nil {
return err
}
queue = append(queue, parents...)
}

acceptedEdges := set.NewSet[ids.ID](0)
acceptedEdges.Add(vtx.serializer.Edge(ctx)...)

// stop vertex should be able to reach all IDs
// that are returned by the "Edge"
if !acceptedFrontier.Equals(acceptedEdges) {
return errUnexpectedEdges
}

// 2. check dependencies of all txs must be subset of transitive paths
prev := transitivePaths.Len()
transitivePaths.Union(dependencies)
if prev != transitivePaths.Len() {
return errUnexpectedDependencyStopVtx
}

return nil
}

func (vtx *uniqueVertex) Height() (uint64, error) {
vtx.refresh()

Expand All @@ -383,16 +247,6 @@ func (vtx *uniqueVertex) Height() (uint64, error) {
return vtx.v.vtx.Height(), nil
}

func (vtx *uniqueVertex) Epoch() (uint32, error) {
vtx.refresh()

if vtx.v.vtx == nil {
return 0, fmt.Errorf("failed to get epoch for vertex with status: %s", vtx.v.status)
}

return vtx.v.vtx.Epoch(), nil
}

func (vtx *uniqueVertex) Txs(ctx context.Context) ([]snowstorm.Tx, error) {
vtx.refresh()

Expand Down
Loading