avalanchego icon indicating copy to clipboard operation
avalanchego copied to clipboard

reward slashing

Open joshua-kim opened this issue 2 years ago • 3 comments

Why this should be merged

Implements reward slashing for subnets + the primary network

How this works

Emits metrics on slash events as defined by vms. RewardValidatorTx looks up the key for the nodeID + txID pair for a given staker to determine whether or not it should be rewarded.

The PrimaryNetwork does not allow slashing, however this feature is enabled for subnets.

How this was tested

Unit test added

joshua-kim avatar Apr 14 '23 20:04 joshua-kim

Failing CI due to an unrelated data race in coreth where we're not holding a lock when modifying the snapshot.

[node4] ==================
[node4] WARNING: DATA RACE
[node4] Write at 0x00c000f67a10 by goroutine 2027:
[node4]   sync/atomic.AddInt64()
[node4]       /opt/hostedtoolcache/go/1.19.8/x64/src/runtime/race_amd64.s:289 +0xb
[node4]   sync/atomic.AddInt64()
[node4]       <autogenerated>:1 +0x1b
[node4]   github.com/ava-labs/coreth/trie.(*Database).node()
[node4]       /home/runner/go/pkg/mod/github.com/ava-labs/[email protected]/trie/database.go:401 +0x1fd
[node4]   github.com/ava-labs/coreth/trie.(*Database).EncodedNode()
[node4]       /home/runner/go/pkg/mod/github.com/ava-labs/[email protected]/trie/database.go:379 +0xbd
[node4]   github.com/ava-labs/coreth/trie.(*Trie).resolveHash()
[node4]       /home/runner/go/pkg/mod/github.com/ava-labs/[email protected]/trie/trie.go:566 +0x13e
[node4]   github.com/ava-labs/coreth/trie.New()
[node4]       /home/runner/go/pkg/mod/github.com/ava-labs/[email protected]/trie/trie.go:115 +0x1d5
[node4]   github.com/ava-labs/coreth/trie.NewStateTrie()
[node4]       /home/runner/go/pkg/mod/github.com/ava-labs/[email protected]/trie/secure_trie.go:81 +0xb1
[node4]   github.com/ava-labs/coreth/core/state.(*cachingDB).OpenTrie()
[node4]       /home/runner/go/pkg/mod/github.com/ava-labs/[email protected]/core/state/database.go:156 +0xac
[node4]   github.com/ava-labs/coreth/core/state.NewWithSnapshot()
[node4]       /home/runner/go/pkg/mod/github.com/ava-labs/[email protected]/core/state/statedb.go:154 +0x8c
[node4]   github.com/ava-labs/coreth/core/state.New()
[node4]       /home/runner/go/pkg/mod/github.com/ava-labs/[email protected]/core/state/statedb.go:146 +0xba
[node4]   github.com/ava-labs/coreth/core.(*BlockChain).StateAt()
[node4]       /home/runner/go/pkg/mod/github.com/ava-labs/[email protected]/core/blockchain_reader.go:248 +0x267
[node4]   github.com/ava-labs/coreth/plugin/evm.(*pushGossiper).queueRegossipTxs()
[node4]       /home/runner/go/pkg/mod/github.com/ava-labs/[email protected]/plugin/evm/gossiper.go:192 +0x183
[node4]   github.com/ava-labs/coreth/plugin/evm.(*pushGossiper).awaitEthTxGossip.func1()
[node4]       /home/runner/go/pkg/mod/github.com/ava-labs/[email protected]/plugin/evm/gossiper.go:243 +0x2dc
[node4]   github.com/ava-labs/avalanchego/utils/logging.(*log).RecoverAndPanic()
[node4]       /home/runner/work/avalanchego/avalanchego/utils/logging/log.go:125 +0x6d
[node4]   github.com/ava-labs/coreth/plugin/evm.(*pushGossiper).awaitEthTxGossip.func2()
[node4]       /home/runner/go/pkg/mod/github.com/ava-labs/[email protected]/plugin/evm/gossiper.go:221 +0x59
[node4] 
[node4] Previous read at 0x00c000f67a10 by goroutine 2520:
[node4]   github.com/ava-labs/coreth/metrics.(*StandardMeter).Snapshot()
[node4]       /home/runner/go/pkg/mod/github.com/ava-labs/[email protected]/metrics/meter.go:244 +0x6e
[node4]   github.com/ava-labs/coreth/metrics/prometheus.gatherer.Gather()
[node4]       /home/runner/go/pkg/mod/github.com/ava-labs/[email protected]/metrics/prometheus/prometheus.go:106 +0x12f9
[node4]   github.com/ava-labs/coreth/metrics/prometheus.(*gatherer).Gather()
[node4]       <autogenerated>:1 +0x5a
[node4]   github.com/ava-labs/avalanchego/api/metrics.(*multiGatherer).Gather()
[node4]       /home/runner/work/avalanchego/avalanchego/api/metrics/multi_gatherer.go:51 +0x1ec
[node4]   github.com/ava-labs/avalanchego/api/metrics.(*optionalGatherer).Gather()
[node4]       /home/runner/work/avalanchego/avalanchego/api/metrics/optional_gatherer.go:49 +0xf3
[node4]   github.com/ava-labs/avalanchego/api/metrics.(*multiGatherer).Gather()
[node4]       /home/runner/work/avalanchego/avalanchego/api/metrics/multi_gatherer.go:51 +0x1ec
[node4]   github.com/ava-labs/avalanchego/api/metrics.(*optionalGatherer).Gather()
[node4]       /home/runner/work/avalanchego/avalanchego/api/metrics/optional_gatherer.go:49 +0xf3
[node4]   github.com/ava-labs/avalanchego/api/metrics.(*multiGatherer).Gather()
[node4]       /home/runner/work/avalanchego/avalanchego/api/metrics/multi_gatherer.go:51 +0x1ec
[node4]   github.com/ava-labs/avalanchego/api/metrics.(*optionalGatherer).Gather()
[node4]       /home/runner/work/avalanchego/avalanchego/api/metrics/optional_gatherer.go:49 +0xf3
[node4]   github.com/ava-labs/avalanchego/api/metrics.(*multiGatherer).Gather()
[node4]       /home/runner/work/avalanchego/avalanchego/api/metrics/multi_gatherer.go:51 +0x1ec
[node4]   github.com/prometheus/client_golang/prometheus.(*noTransactionGatherer).Gather()
[node4]       /home/runner/go/pkg/mod/github.com/prometheus/[email protected]/prometheus/registry.go:1042 +0x44
[node4]   github.com/prometheus/client_golang/prometheus/promhttp.HandlerForTransactional.func1()
[node4]       /home/runner/go/pkg/mod/github.com/prometheus/[email protected]/prometheus/promhttp/http.go:135 +0x107
[node4]   net/http.HandlerFunc.ServeHTTP()
[node4]       /opt/hostedtoolcache/go/1.19.8/x64/src/net/http/server.go:2109 +0x4d
[node4]   github.com/ava-labs/avalanchego/api/server.(*metrics).wrapHandler.func1()
[node4]       /home/runner/work/avalanchego/avalanchego/api/server/metrics.go:72 +0x1c8
[node4]   net/http.HandlerFunc.ServeHTTP()
[node4]       /opt/hostedtoolcache/go/1.19.8/x64/src/net/http/server.go:2109 +0x4d
[node4]   github.com/gorilla/mux.(*Router).ServeHTTP()
[node4]       /home/runner/go/pkg/mod/github.com/gorilla/[email protected]/mux.go:210 +0x371
[node4]   github.com/ava-labs/avalanchego/api/server.(*router).ServeHTTP()
[node4]       /home/runner/work/avalanchego/avalanchego/api/server/router.go:45 +0xcf
[node4]   github.com/rs/cors.(*Cors).Handler.func1()
[node4]       /home/runner/go/pkg/mod/github.com/rs/[email protected]/cors.go:219 +0x32a
[node4]   net/http.HandlerFunc.ServeHTTP()
[node4]       /opt/hostedtoolcache/go/1.19.8/x64/src/net/http/server.go:2109 +0x4d
[node4]   github.com/NYTimes/gziphandler.GzipHandlerWithOpts.func1.1()
[node4]       /home/runner/go/pkg/mod/github.com/!n!y!times/[email protected]/gzip.go:336 +0x457
[node4]   net/http.HandlerFunc.ServeHTTP()
[node4]       /opt/hostedtoolcache/go/1.19.8/x64/src/net/http/server.go:2109 +0x4d
[node4]   github.com/ava-labs/avalanchego/api/server.New.func1()
[node4]       /home/runner/work/avalanchego/avalanchego/api/server/server.go:139 +0x19c
[node4]   net/http.HandlerFunc.ServeHTTP()
[node4]       /opt/hostedtoolcache/go/1.19.8/x64/src/net/http/server.go:2109 +0x4d
[node4]   net/http.serverHandler.ServeHTTP()
[node4]       /opt/hostedtoolcache/go/1.19.8/x64/src/net/http/server.go:2947 +0x641
[node4]   net/http.(*conn).serve()
[node4]       /opt/hostedtoolcache/go/1.19.8/x64/src/net/http/server.go:1991 +0xbe4
[node4]   net/http.(*Server).Serve.func3()
[node4]       /opt/hostedtoolcache/go/1.19.8/x64/src/net/http/server.go:3102 +0x58

joshua-kim avatar Apr 20 '23 17:04 joshua-kim

This PR has become stale because it has been open for 30 days with no activity. Adding the lifecycle/frozen label will cause this PR to ignore lifecycle events.

github-actions[bot] avatar Mar 31 '24 00:03 github-actions[bot]

Moving to draft + freezing since we want something more generic than just a slash (ideally something where a VM can define + modify node scores).

joshua-kim avatar Apr 02 '24 14:04 joshua-kim