mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 13:28:01 -05:00
fix state equality checks
This commit is contained in:
@@ -5,5 +5,8 @@ go_library(
|
||||
srcs = ["types.go"],
|
||||
importpath = "github.com/prysmaticlabs/prysm/v4/beacon-chain/state/state-native/types",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["@com_github_pkg_errors//:go_default_library"],
|
||||
deps = [
|
||||
"//consensus-types:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
consensus_types "github.com/prysmaticlabs/prysm/v4/consensus-types"
|
||||
)
|
||||
|
||||
// FieldInfo contains various information about a state's field.
|
||||
@@ -228,20 +227,5 @@ const (
|
||||
HistoricalSummaries
|
||||
)
|
||||
|
||||
// StateEnumerator is a thread-safe counter of all states created since the node's start.
|
||||
type StateEnumerator struct {
|
||||
counter uint64
|
||||
lock sync.RWMutex
|
||||
}
|
||||
|
||||
// Inc increments the number of states and returns the new state count.
|
||||
func (c *StateEnumerator) Inc() uint64 {
|
||||
c.lock.Lock()
|
||||
c.counter++
|
||||
v := c.counter
|
||||
c.lock.Unlock()
|
||||
return v
|
||||
}
|
||||
|
||||
// Enumerator keeps track of the number of states created since the node's start.
|
||||
var Enumerator = StateEnumerator{}
|
||||
var Enumerator consensus_types.Enumerator = &consensus_types.ThreadSafeEnumerator{}
|
||||
|
||||
@@ -60,6 +60,7 @@ go_test(
|
||||
"history_test.go",
|
||||
"hot_state_cache_test.go",
|
||||
"init_test.go",
|
||||
"main_test.go",
|
||||
"migrate_test.go",
|
||||
"mock_test.go",
|
||||
"replay_test.go",
|
||||
@@ -77,6 +78,7 @@ go_test(
|
||||
"//beacon-chain/forkchoice/doubly-linked-tree:go_default_library",
|
||||
"//beacon-chain/state:go_default_library",
|
||||
"//beacon-chain/state/state-native:go_default_library",
|
||||
"//beacon-chain/state/state-native/types:go_default_library",
|
||||
"//config/params:go_default_library",
|
||||
"//consensus-types/blocks:go_default_library",
|
||||
"//consensus-types/blocks/testing:go_default_library",
|
||||
|
||||
13
beacon-chain/state/stategen/main_test.go
Normal file
13
beacon-chain/state/stategen/main_test.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package stategen
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v4/beacon-chain/state/state-native/types"
|
||||
"github.com/prysmaticlabs/prysm/v4/consensus-types/mock"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
types.Enumerator = &mock.ZeroEnumerator{}
|
||||
m.Run()
|
||||
}
|
||||
@@ -2,7 +2,10 @@ load("@prysm//tools/go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["block.go"],
|
||||
srcs = [
|
||||
"block.go",
|
||||
"enumerator.go",
|
||||
],
|
||||
importpath = "github.com/prysmaticlabs/prysm/v4/consensus-types/mock",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
|
||||
9
consensus-types/mock/enumerator.go
Normal file
9
consensus-types/mock/enumerator.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package mock
|
||||
|
||||
// ZeroEnumerator always returns zero.
|
||||
type ZeroEnumerator struct{}
|
||||
|
||||
// Inc --
|
||||
func (c *ZeroEnumerator) Inc() uint64 {
|
||||
return 0
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package consensus_types
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
errors2 "github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/prysm/v4/runtime/version"
|
||||
@@ -19,3 +20,23 @@ var (
|
||||
func ErrNotSupported(funcName string, ver int) error {
|
||||
return errors2.Wrap(ErrUnsupportedField, fmt.Sprintf("%s is not supported for %s", funcName, version.String(ver)))
|
||||
}
|
||||
|
||||
// Enumerator keeps track of the number of objects created since the node's start.
|
||||
type Enumerator interface {
|
||||
Inc() uint64
|
||||
}
|
||||
|
||||
// ThreadSafeEnumerator is a thread-safe counter of all objects created since the node's start.
|
||||
type ThreadSafeEnumerator struct {
|
||||
counter uint64
|
||||
lock sync.RWMutex
|
||||
}
|
||||
|
||||
// Inc increments the enumerator and returns the new object count.
|
||||
func (c *ThreadSafeEnumerator) Inc() uint64 {
|
||||
c.lock.Lock()
|
||||
c.counter++
|
||||
v := c.counter
|
||||
c.lock.Unlock()
|
||||
return v
|
||||
}
|
||||
|
||||
@@ -70,6 +70,7 @@ go_test(
|
||||
"capella_block_test.go",
|
||||
"deposits_test.go",
|
||||
"helpers_test.go",
|
||||
"main_test.go",
|
||||
"state_test.go",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
@@ -80,9 +81,11 @@ go_test(
|
||||
"//beacon-chain/core/time:go_default_library",
|
||||
"//beacon-chain/core/transition:go_default_library",
|
||||
"//beacon-chain/core/transition/stateutils:go_default_library",
|
||||
"//beacon-chain/state/state-native/types:go_default_library",
|
||||
"//config/fieldparams:go_default_library",
|
||||
"//config/params:go_default_library",
|
||||
"//consensus-types/blocks:go_default_library",
|
||||
"//consensus-types/mock:go_default_library",
|
||||
"//consensus-types/primitives:go_default_library",
|
||||
"//crypto/hash:go_default_library",
|
||||
"//encoding/bytesutil:go_default_library",
|
||||
|
||||
13
testing/util/main_test.go
Normal file
13
testing/util/main_test.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v4/beacon-chain/state/state-native/types"
|
||||
"github.com/prysmaticlabs/prysm/v4/consensus-types/mock"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
types.Enumerator = &mock.ZeroEnumerator{}
|
||||
m.Run()
|
||||
}
|
||||
Reference in New Issue
Block a user