From 4ac34ad2968d37adbac9cff2eaaa45568e4bacfb Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Sat, 6 Jun 2020 23:52:44 -0400 Subject: [PATCH] nits --- snow/engine/avalanche/vertex_heap.go | 14 +++++++++++--- snow/engine/avalanche/vertex_heap_test.go | 2 +- snow/engine/common/vm.go | 4 ++-- vms/avm/vm.go | 7 +++++-- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/snow/engine/avalanche/vertex_heap.go b/snow/engine/avalanche/vertex_heap.go index 7c68294..487ba0a 100644 --- a/snow/engine/avalanche/vertex_heap.go +++ b/snow/engine/avalanche/vertex_heap.go @@ -18,13 +18,14 @@ type priorityQueue []*vertexItem func (pq priorityQueue) Len() int { return len(pq) } +// Returns true if the vertex at index i has greater height than the vertex at +// index j. func (pq priorityQueue) Less(i, j int) bool { statusI := pq[i].vertex.Status() statusJ := pq[j].vertex.Status() - // Put unknown vertices at the front of the heap to ensure - // once we have made it below a certain height in DAG traversal - // we do not need to reset + // Put unknown vertices at the front of the heap to ensure once we have made + // it below a certain height in DAG traversal we do not need to reset if !statusI.Fetched() { return true } @@ -40,6 +41,7 @@ func (pq priorityQueue) Swap(i, j int) { pq[j].index = j } +// Push adds an item to this priority queue. x must have type *vertexItem func (pq *priorityQueue) Push(x interface{}) { n := len(*pq) item := x.(*vertexItem) @@ -47,6 +49,7 @@ func (pq *priorityQueue) Push(x interface{}) { *pq = append(*pq, item) } +// Pop returns the last item in this priorityQueue func (pq *priorityQueue) Pop() interface{} { old := *pq n := len(old) @@ -84,6 +87,8 @@ func (vh *maxHeightVertexHeap) Clear() { vh.elementIDs.Clear() } +// Push adds an element to this heap. Returns true if the element was added. +// Returns false if it was already in the heap. func (vh *maxHeightVertexHeap) Push(vtx avalanche.Vertex) bool { vtxID := vtx.ID() if vh.elementIDs.Contains(vtxID) { @@ -98,6 +103,9 @@ func (vh *maxHeightVertexHeap) Push(vtx avalanche.Vertex) bool { return true } +// If there are any vertices in this heap with status Unknown, removes one such +// vertex and returns it. Otherwise, removes and returns the vertex in this heap +// with the greatest height. func (vh *maxHeightVertexHeap) Pop() avalanche.Vertex { vtx := heap.Pop(vh.heap).(*vertexItem).vertex vh.elementIDs.Remove(vtx.ID()) diff --git a/snow/engine/avalanche/vertex_heap_test.go b/snow/engine/avalanche/vertex_heap_test.go index f8ea16f..0713aa0 100644 --- a/snow/engine/avalanche/vertex_heap_test.go +++ b/snow/engine/avalanche/vertex_heap_test.go @@ -49,7 +49,7 @@ func TestUniqueVertexHeapReturnsOrdered(t *testing.T) { vtxZ := h.Pop() if !vtxZ.ID().Equals(vtx4.ID()) { - t.Fatalf("Heap did not pop unknonw element first") + t.Fatalf("Heap did not pop unknown element first") } vtxA := h.Pop() diff --git a/snow/engine/common/vm.go b/snow/engine/common/vm.go index 405f80f..87860da 100644 --- a/snow/engine/common/vm.go +++ b/snow/engine/common/vm.go @@ -36,10 +36,10 @@ type VM interface { fxs []*Fx, ) error - // Bootstrapping is called when the node is starting to bootstrap. + // Bootstrapping is called when the node is starting to bootstrap this chain. Bootstrapping() error - // Bootstrapped is called when the node is exiting bootstrapping. + // Bootstrapped is called when the node is done bootstrapping this chain. Bootstrapped() error // Shutdown is called when the node is shutting down. diff --git a/vms/avm/vm.go b/vms/avm/vm.go index 7ec3944..1b92f6a 100644 --- a/vms/avm/vm.go +++ b/vms/avm/vm.go @@ -68,6 +68,7 @@ type VM struct { // State management state *prefixedState + // Set to true once this VM is marked as `Bootstrapped` by the engine bootstrapped bool // Transaction issuing @@ -200,7 +201,8 @@ func (vm *VM) Initialize( return vm.db.Commit() } -// Bootstrapping marks this VM as bootstrapping +// Bootstrapping is called by the consensus engine when it starts bootstrapping +// this chain func (vm *VM) Bootstrapping() error { for _, fx := range vm.fxs { if err := fx.Fx.Bootstrapping(); err != nil { @@ -210,7 +212,8 @@ func (vm *VM) Bootstrapping() error { return nil } -// Bootstrapped marks this VM as bootstrapped +// Bootstrapped is called by the consensus engine when it is done bootstrapping +// this chain func (vm *VM) Bootstrapped() error { for _, fx := range vm.fxs { if err := fx.Fx.Bootstrapped(); err != nil {