Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit b44feeb
Author: Stephen Buttolph <stephen@avalabs.org>
Date:   Wed Apr 3 19:49:53 2024 -0400

    Remove `linked.Hashmap` locking (#2911)

commit 0fea82e
Author: Stephen Buttolph <stephen@avalabs.org>
Date:   Wed Apr 3 19:00:22 2024 -0400

    Avoid allocating new list entries (#2910)

commit d3a74eb
Author: Stephen Buttolph <stephen@avalabs.org>
Date:   Wed Apr 3 17:57:33 2024 -0400

    Use generic linked list (#2909)

commit 93b9000
Author: Stephen Buttolph <stephen@avalabs.org>
Date:   Wed Apr 3 17:29:21 2024 -0400

    Remove full message from error logs (#2912)

commit e1954bb
Author: Stephen Buttolph <stephen@avalabs.org>
Date:   Wed Apr 3 17:27:29 2024 -0400

    Implement generic `linked.List` (#2908)

    Co-authored-by: dhrubabasu <7675102+dhrubabasu@users.noreply.github.com>

commit f786a24
Author: marun <maru.newby@avalabs.org>
Date:   Wed Apr 3 19:18:29 2024 +0200

    [tmpnet] Misc cleanup to support xsvm warp test PR (#2903)

commit d103931
Author: Stephen Buttolph <stephen@avalabs.org>
Date:   Wed Apr 3 12:47:16 2024 -0400

    Rename linkedhashmap package to `linked` (#2907)

commit d4507bf
Author: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Date:   Tue Apr 2 20:31:00 2024 -0400

    Remove AddEphemeralNode (#2887)

    Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>

commit d7452d3
Author: Stephen Buttolph <stephen@avalabs.org>
Date:   Tue Apr 2 20:21:29 2024 -0400

    Reuse key buffers during hashing (#2902)

commit 5be62de
Author: Stephen Buttolph <stephen@avalabs.org>
Date:   Tue Apr 2 17:16:42 2024 -0400

    Conditionally allocate WaitGroup memory (#2901)

commit e7b14e4
Author: Stephen Buttolph <stephen@avalabs.org>
Date:   Tue Apr 2 16:50:28 2024 -0400

    Move bootstrapping queue out of common (#2856)

commit 6699924
Author: Stephen Buttolph <stephen@avalabs.org>
Date:   Tue Apr 2 16:44:05 2024 -0400

    Optimize key creation in hashing (#2899)

commit e4b82cf
Author: Stephen Buttolph <stephen@avalabs.org>
Date:   Tue Apr 2 16:23:45 2024 -0400

    Remove usage of bytes.Buffer and bytes.Reader (#2896)

commit 434db9c
Author: Stephen Buttolph <stephen@avalabs.org>
Date:   Tue Apr 2 14:41:41 2024 -0400

    Improve tracing of merkledb trie updates (#2897)

commit f7def4d
Author: Stephen Buttolph <stephen@avalabs.org>
Date:   Tue Apr 2 13:47:56 2024 -0400

    Improve performance of marshalling small keys (#2895)

commit 00d4e0a
Author: Stephen Buttolph <stephen@avalabs.org>
Date:   Tue Apr 2 11:21:26 2024 -0400

    Optimize hashing of leaf nodes (#2894)

commit 617a9e2
Author: Stephen Buttolph <stephen@avalabs.org>
Date:   Tue Apr 2 11:01:46 2024 -0400

    Interval tree syncing integration (#2855)

commit 9a0c852
Author: Stephen Buttolph <stephen@avalabs.org>
Date:   Tue Apr 2 09:38:12 2024 -0400

    Remove memory alloc from encodeDBNode (#2893)

commit 4163dce
Author: Stephen Buttolph <stephen@avalabs.org>
Date:   Fri Mar 29 18:20:48 2024 -0400

    Move functions so that encode and decode are adjacent (#2892)

commit ce8253c
Author: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com>
Date:   Fri Mar 29 16:56:45 2024 -0400

    [vms/platformvm] Miscellaneous testing cleanups (#2891)

commit 2dbc9ba
Author: Stephen Buttolph <stephen@avalabs.org>
Date:   Fri Mar 29 16:20:53 2024 -0400

    Optimize merkledb hashing (#2886)

commit d046f29
Author: marun <maru.newby@avalabs.org>
Date:   Fri Mar 29 15:34:16 2024 +0100

    `ci`: Skip monitoring if secrets are not present (#2880)

commit 835d9ff
Author: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com>
Date:   Fri Mar 29 09:39:54 2024 -0400

    [vms/platformvm] Minimize exported functions in `txstest` (#2888)

commit b01d98d
Author: Stephen Buttolph <stephen@avalabs.org>
Date:   Fri Mar 29 00:43:33 2024 -0400

    Remove merkledb codec struct (#2883)

commit 10b881f
Author: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com>
Date:   Thu Mar 28 21:54:25 2024 -0400

    [components/avax] Remove `AtomicUTXOManager` interface (#2884)

commit 2a0bd08
Author: Stephen Buttolph <stephen@avalabs.org>
Date:   Thu Mar 28 19:53:12 2024 -0400

    Optimize encodeUint (#2882)

commit ec347cb
Author: Alberto Benegiamo <alberto.benegiamo@gmail.com>
Date:   Fri Mar 29 00:19:14 2024 +0100

    [vms/platformvm] Use `wallet` sdk in `txstest.Builder` (#2751)

    Co-authored-by: Stephen Buttolph <stephen@avalabs.org>
    Co-authored-by: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com>

commit 70cd8e1
Author: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com>
Date:   Thu Mar 28 17:27:12 2024 -0400

    [vms/platformvm] Declare `maxPageSize` in `service.go` (#2881)

Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
  • Loading branch information
joshua-kim committed Apr 4, 2024
1 parent d529a1b commit fe914c4
Show file tree
Hide file tree
Showing 97 changed files with 6,129 additions and 5,192 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,22 @@ jobs:
shell: bash
run: ./scripts/build.sh -r
- name: Start prometheus
# Only run for the original repo; a forked repo won't have access to the monitoring credentials
if: (github.event.pull_request.head.repo.full_name == github.repository) || (github.event.repository.fork == false)
shell: bash
run: bash -x ./scripts/run_prometheus.sh
env:
PROMETHEUS_ID: ${{ secrets.PROMETHEUS_ID }}
PROMETHEUS_PASSWORD: ${{ secrets.PROMETHEUS_PASSWORD }}
- name: Start promtail
if: (github.event.pull_request.head.repo.full_name == github.repository) || (github.event.repository.fork == false)
shell: bash
run: bash -x ./scripts/run_promtail.sh
env:
LOKI_ID: ${{ secrets.LOKI_ID }}
LOKI_PASSWORD: ${{ secrets.LOKI_PASSWORD }}
- name: Notify of metrics availability
if: (github.event.pull_request.head.repo.full_name == github.repository) || (github.event.repository.fork == false)
shell: bash
run: .github/workflows/notify-metrics-availability.sh
env:
Expand Down Expand Up @@ -118,18 +122,22 @@ jobs:
shell: bash
run: ./scripts/build.sh -r
- name: Start prometheus
# Only run for the original repo; a forked repo won't have access to the monitoring credentials
if: (github.event.pull_request.head.repo.full_name == github.repository) || (github.event.repository.fork == false)
shell: bash
run: bash -x ./scripts/run_prometheus.sh
env:
PROMETHEUS_ID: ${{ secrets.PROMETHEUS_ID }}
PROMETHEUS_PASSWORD: ${{ secrets.PROMETHEUS_PASSWORD }}
- name: Start promtail
if: (github.event.pull_request.head.repo.full_name == github.repository) || (github.event.repository.fork == false)
shell: bash
run: bash -x ./scripts/run_promtail.sh
env:
LOKI_ID: ${{ secrets.LOKI_ID }}
LOKI_PASSWORD: ${{ secrets.LOKI_PASSWORD }}
- name: Notify of metrics availability
if: (github.event.pull_request.head.repo.full_name == github.repository) || (github.event.repository.fork == false)
shell: bash
run: .github/workflows/notify-metrics-availability.sh
env:
Expand Down Expand Up @@ -167,18 +175,22 @@ jobs:
shell: bash
run: ./scripts/build.sh
- name: Start prometheus
# Only run for the original repo; a forked repo won't have access to the monitoring credentials
if: (github.event.pull_request.head.repo.full_name == github.repository) || (github.event.repository.fork == false)
shell: bash
run: bash -x ./scripts/run_prometheus.sh
env:
PROMETHEUS_ID: ${{ secrets.PROMETHEUS_ID }}
PROMETHEUS_PASSWORD: ${{ secrets.PROMETHEUS_PASSWORD }}
- name: Start promtail
if: (github.event.pull_request.head.repo.full_name == github.repository) || (github.event.repository.fork == false)
shell: bash
run: bash -x ./scripts/run_promtail.sh
env:
LOKI_ID: ${{ secrets.LOKI_ID }}
LOKI_PASSWORD: ${{ secrets.LOKI_PASSWORD }}
- name: Notify of metrics availability
if: (github.event.pull_request.head.repo.full_name == github.repository) || (github.event.repository.fork == false)
shell: bash
run: .github/workflows/notify-metrics-availability.sh
env:
Expand Down
10 changes: 6 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,14 @@ linters-settings:
rules:
packages:
deny:
- pkg: "io/ioutil"
desc: io/ioutil is deprecated. Use package io or os instead.
- pkg: "github.com/stretchr/testify/assert"
desc: github.com/stretchr/testify/require should be used instead.
- pkg: "container/list"
desc: github.com/ava-labs/avalanchego/utils/linked should be used instead.
- pkg: "github.com/golang/mock/gomock"
desc: go.uber.org/mock/gomock should be used instead.
- pkg: "github.com/stretchr/testify/assert"
desc: github.com/stretchr/testify/require should be used instead.
- pkg: "io/ioutil"
desc: io/ioutil is deprecated. Use package io or os instead.
errorlint:
# Check for plain type assertions and type switches.
asserts: false
Expand Down
8 changes: 4 additions & 4 deletions cache/lru_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"sync"

"github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/linkedhashmap"
"github.com/ava-labs/avalanchego/utils/linked"
)

var _ Cacher[struct{}, struct{}] = (*LRU[struct{}, struct{}])(nil)
Expand All @@ -17,7 +17,7 @@ var _ Cacher[struct{}, struct{}] = (*LRU[struct{}, struct{}])(nil)
// done, based on evicting the least recently used value.
type LRU[K comparable, V any] struct {
lock sync.Mutex
elements linkedhashmap.LinkedHashmap[K, V]
elements *linked.Hashmap[K, V]
// If set to <= 0, will be set internally to 1.
Size int
}
Expand Down Expand Up @@ -92,7 +92,7 @@ func (c *LRU[K, _]) evict(key K) {
}

func (c *LRU[K, V]) flush() {
c.elements = linkedhashmap.New[K, V]()
c.elements = linked.NewHashmap[K, V]()
}

func (c *LRU[_, _]) len() int {
Expand All @@ -112,7 +112,7 @@ func (c *LRU[_, _]) portionFilled() float64 {
// in the cache == [c.size] if necessary.
func (c *LRU[K, V]) resize() {
if c.elements == nil {
c.elements = linkedhashmap.New[K, V]()
c.elements = linked.NewHashmap[K, V]()
}
if c.Size <= 0 {
c.Size = 1
Expand Down
8 changes: 4 additions & 4 deletions cache/lru_sized_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"sync"

"github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/linkedhashmap"
"github.com/ava-labs/avalanchego/utils/linked"
)

var _ Cacher[struct{}, any] = (*sizedLRU[struct{}, any])(nil)
Expand All @@ -17,15 +17,15 @@ var _ Cacher[struct{}, any] = (*sizedLRU[struct{}, any])(nil)
// honored, based on evicting the least recently used value.
type sizedLRU[K comparable, V any] struct {
lock sync.Mutex
elements linkedhashmap.LinkedHashmap[K, V]
elements *linked.Hashmap[K, V]
maxSize int
currentSize int
size func(K, V) int
}

func NewSizedLRU[K comparable, V any](maxSize int, size func(K, V) int) Cacher[K, V] {
return &sizedLRU[K, V]{
elements: linkedhashmap.New[K, V](),
elements: linked.NewHashmap[K, V](),
maxSize: maxSize,
size: size,
}
Expand Down Expand Up @@ -113,7 +113,7 @@ func (c *sizedLRU[K, _]) evict(key K) {
}

func (c *sizedLRU[K, V]) flush() {
c.elements = linkedhashmap.New[K, V]()
c.elements = linked.NewHashmap[K, V]()
c.currentSize = 0
}

Expand Down
33 changes: 17 additions & 16 deletions cache/unique_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
package cache

import (
"container/list"
"sync"

"github.com/ava-labs/avalanchego/utils/linked"
)

var _ Deduplicator[struct{}, Evictable[struct{}]] = (*EvictableLRU[struct{}, Evictable[struct{}]])(nil)

// EvictableLRU is an LRU cache that notifies the objects when they are evicted.
type EvictableLRU[K comparable, _ Evictable[K]] struct {
type EvictableLRU[K comparable, V Evictable[K]] struct {
lock sync.Mutex
entryMap map[K]*list.Element
entryList *list.List
entryMap map[K]*linked.ListElement[V]
entryList *linked.List[V]
Size int
}

Expand All @@ -32,12 +33,12 @@ func (c *EvictableLRU[_, _]) Flush() {
c.flush()
}

func (c *EvictableLRU[K, _]) init() {
func (c *EvictableLRU[K, V]) init() {
if c.entryMap == nil {
c.entryMap = make(map[K]*list.Element)
c.entryMap = make(map[K]*linked.ListElement[V])
}
if c.entryList == nil {
c.entryList = list.New()
c.entryList = linked.NewList[V]()
}
if c.Size <= 0 {
c.Size = 1
Expand All @@ -49,9 +50,8 @@ func (c *EvictableLRU[_, V]) resize() {
e := c.entryList.Front()
c.entryList.Remove(e)

val := e.Value.(V)
delete(c.entryMap, val.Key())
val.Evict()
delete(c.entryMap, e.Value.Key())
e.Value.Evict()
}
}

Expand All @@ -65,20 +65,21 @@ func (c *EvictableLRU[_, V]) deduplicate(value V) V {
e = c.entryList.Front()
c.entryList.MoveToBack(e)

val := e.Value.(V)
delete(c.entryMap, val.Key())
val.Evict()
delete(c.entryMap, e.Value.Key())
e.Value.Evict()

e.Value = value
} else {
e = c.entryList.PushBack(value)
e = &linked.ListElement[V]{
Value: value,
}
c.entryList.PushBack(e)
}
c.entryMap[key] = e
} else {
c.entryList.MoveToBack(e)

val := e.Value.(V)
value = val
value = e.Value
}
return value
}
Expand Down
19 changes: 5 additions & 14 deletions chains/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import (
"github.com/ava-labs/avalanchego/network"
"github.com/ava-labs/avalanchego/proto/pb/p2p"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/snow/engine/avalanche/bootstrap/queue"
"github.com/ava-labs/avalanchego/snow/engine/avalanche/state"
"github.com/ava-labs/avalanchego/snow/engine/avalanche/vertex"
"github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/snow/engine/common/queue"
"github.com/ava-labs/avalanchego/snow/engine/common/tracker"
"github.com/ava-labs/avalanchego/snow/engine/snowman/block"
"github.com/ava-labs/avalanchego/snow/engine/snowman/syncer"
Expand Down Expand Up @@ -85,10 +85,10 @@ var (
VertexDBPrefix = []byte("vertex")
VertexBootstrappingDBPrefix = []byte("vertex_bs")
TxBootstrappingDBPrefix = []byte("tx_bs")
BlockBootstrappingDBPrefix = []byte("block_bs")
BlockBootstrappingDBPrefix = []byte("interval_block_bs")

// Bootstrapping prefixes for ChainVMs
ChainBootstrappingDBPrefix = []byte("bs")
ChainBootstrappingDBPrefix = []byte("interval_bs")

errUnknownVMType = errors.New("the vm should have type avalanche.DAGVM or snowman.ChainVM")
errCreatePlatformVM = errors.New("attempted to create a chain running the PlatformVM")
Expand Down Expand Up @@ -580,10 +580,6 @@ func (m *manager) createAvalancheChain(
if err != nil {
return nil, err
}
blockBlocker, err := queue.NewWithMissing(blockBootstrappingDB, "block", ctx.Registerer)
if err != nil {
return nil, err
}

// Passes messages from the avalanche engines to the network
avalancheMessageSender, err := sender.New(
Expand Down Expand Up @@ -844,7 +840,7 @@ func (m *manager) createAvalancheChain(
BootstrapTracker: sb,
Timer: h,
AncestorsMaxContainersReceived: m.BootstrapAncestorsMaxContainersReceived,
Blocked: blockBlocker,
DB: blockBootstrappingDB,
VM: snowmanVM,
}
var snowmanBootstrapper common.BootstrapableEngine
Expand Down Expand Up @@ -959,11 +955,6 @@ func (m *manager) createSnowmanChain(
vmDB := prefixdb.New(VMDBPrefix, prefixDB)
bootstrappingDB := prefixdb.New(ChainBootstrappingDBPrefix, prefixDB)

blocked, err := queue.NewWithMissing(bootstrappingDB, "block", ctx.Registerer)
if err != nil {
return nil, err
}

// Passes messages from the consensus engine to the network
messageSender, err := sender.New(
ctx,
Expand Down Expand Up @@ -1190,7 +1181,7 @@ func (m *manager) createSnowmanChain(
BootstrapTracker: sb,
Timer: h,
AncestorsMaxContainersReceived: m.BootstrapAncestorsMaxContainersReceived,
Blocked: blocked,
DB: bootstrappingDB,
VM: snowmanVM,
Bootstrapped: bootstrapFunc,
}
Expand Down
6 changes: 3 additions & 3 deletions network/throttling/inbound_msg_byte_throttler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/linkedhashmap"
"github.com/ava-labs/avalanchego/utils/linked"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/metric"
"github.com/ava-labs/avalanchego/utils/wrappers"
Expand All @@ -39,7 +39,7 @@ func newInboundMsgByteThrottler(
nodeToVdrBytesUsed: make(map[ids.NodeID]uint64),
nodeToAtLargeBytesUsed: make(map[ids.NodeID]uint64),
},
waitingToAcquire: linkedhashmap.New[uint64, *msgMetadata](),
waitingToAcquire: linked.NewHashmap[uint64, *msgMetadata](),
nodeToWaitingMsgID: make(map[ids.NodeID]uint64),
}
return t, t.metrics.initialize(namespace, registerer)
Expand Down Expand Up @@ -67,7 +67,7 @@ type inboundMsgByteThrottler struct {
// Node ID --> Msg ID for a message this node is waiting to acquire
nodeToWaitingMsgID map[ids.NodeID]uint64
// Msg ID --> *msgMetadata
waitingToAcquire linkedhashmap.LinkedHashmap[uint64, *msgMetadata]
waitingToAcquire *linked.Hashmap[uint64, *msgMetadata]
// Invariant: The node is only waiting on a single message at a time
//
// Invariant: waitingToAcquire.Get(nodeToWaitingMsgIDs[nodeID])
Expand Down
3 changes: 3 additions & 0 deletions network/throttling/inbound_msg_byte_throttler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,13 +422,16 @@ func TestMsgThrottlerNextMsg(t *testing.T) {

// Release 1 byte
throttler.release(&msgMetadata{msgSize: 1}, vdr1ID)

// Byte should have gone toward next validator message
throttler.lock.Lock()
require.Equal(2, throttler.waitingToAcquire.Len())
require.Contains(throttler.nodeToWaitingMsgID, vdr1ID)
firstMsgID := throttler.nodeToWaitingMsgID[vdr1ID]
firstMsg, exists := throttler.waitingToAcquire.Get(firstMsgID)
require.True(exists)
require.Equal(maxBytes-2, firstMsg.bytesNeeded)
throttler.lock.Unlock()

select {
case <-doneVdr:
Expand Down
6 changes: 3 additions & 3 deletions snow/consensus/snowman/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/choices"
"github.com/ava-labs/avalanchego/utils/linkedhashmap"
"github.com/ava-labs/avalanchego/utils/linked"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/metric"
"github.com/ava-labs/avalanchego/utils/wrappers"
Expand All @@ -34,7 +34,7 @@ type metrics struct {
// processingBlocks keeps track of the [processingStart] that each block was
// issued into the consensus instance. This is used to calculate the amount
// of time to accept or reject the block.
processingBlocks linkedhashmap.LinkedHashmap[ids.ID, processingStart]
processingBlocks *linked.Hashmap[ids.ID, processingStart]

// numProcessing keeps track of the number of processing blocks
numProcessing prometheus.Gauge
Expand Down Expand Up @@ -90,7 +90,7 @@ func newMetrics(
Help: "timestamp of the last accepted block in unix seconds",
}),

processingBlocks: linkedhashmap.New[ids.ID, processingStart](),
processingBlocks: linked.NewHashmap[ids.ID, processingStart](),

// e.g.,
// "avalanche_X_blks_processing" reports how many blocks are currently processing
Expand Down

0 comments on commit fe914c4

Please sign in to comment.