proper fail for worker count
This commit is contained in:
parent
d711fa7d7f
commit
03018fa58a
@ -23,6 +23,7 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"sync"
|
||||
"math/bits"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/state"
|
||||
@ -58,14 +59,17 @@ type iterPair struct {
|
||||
}
|
||||
|
||||
// NewBuilder is used to create a statediff builder
|
||||
func NewBuilder(stateCache state.Database, workers uint) Builder {
|
||||
func NewBuilder(stateCache state.Database, workers uint) (Builder, error) {
|
||||
if workers == 0 {
|
||||
workers = 1
|
||||
}
|
||||
if bits.OnesCount(workers) != 1 {
|
||||
return nil, fmt.Errorf("workers must be a power of 2")
|
||||
}
|
||||
return &builder{
|
||||
stateCache: stateCache, // state cache is safe for concurrent reads
|
||||
numWorkers: workers,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
// BuildStateTrieObject builds a state trie object from the provided block
|
||||
|
@ -669,7 +669,7 @@ func TestBuilder(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, workers := range workerCounts {
|
||||
builder := pkg.NewBuilder(chain.StateCache(), workers)
|
||||
builder, _ = pkg.NewBuilder(chain.StateCache(), workers)
|
||||
for _, test := range tests {
|
||||
diff, err := builder.BuildStateDiffObject(test.startingArguments, params)
|
||||
if err != nil {
|
||||
@ -928,7 +928,7 @@ func TestBuilderWithIntermediateNodes(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, workers := range workerCounts {
|
||||
builder = pkg.NewBuilder(chain.StateCache(), workers)
|
||||
builder, _ = pkg.NewBuilder(chain.StateCache(), workers)
|
||||
for i, test := range tests {
|
||||
diff, err := builder.BuildStateDiffObject(test.startingArguments, params)
|
||||
if err != nil {
|
||||
@ -1113,7 +1113,7 @@ func TestBuilderWithWatchedAddressList(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, workers := range workerCounts {
|
||||
builder = pkg.NewBuilder(chain.StateCache(), workers)
|
||||
builder, _ = pkg.NewBuilder(chain.StateCache(), workers)
|
||||
for _, test := range tests {
|
||||
diff, err := builder.BuildStateDiffObject(test.startingArguments, params)
|
||||
if err != nil {
|
||||
@ -1272,7 +1272,7 @@ func TestBuilderWithWatchedAddressAndStorageKeyList(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, workers := range workerCounts {
|
||||
builder = pkg.NewBuilder(chain.StateCache(), workers)
|
||||
builder, _ = pkg.NewBuilder(chain.StateCache(), workers)
|
||||
for _, test := range tests {
|
||||
diff, err := builder.BuildStateDiffObject(test.startingArguments, params)
|
||||
if err != nil {
|
||||
@ -1481,7 +1481,7 @@ func TestBuilderWithRemovedAccountAndStorage(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, workers := range workerCounts {
|
||||
builder = pkg.NewBuilder(chain.StateCache(), workers)
|
||||
builder, _ = pkg.NewBuilder(chain.StateCache(), workers)
|
||||
for _, test := range tests {
|
||||
diff, err := builder.BuildStateDiffObject(test.startingArguments, params)
|
||||
if err != nil {
|
||||
@ -1667,7 +1667,7 @@ func TestBuilderWithRemovedAccountAndStorageWithoutIntermediateNodes(t *testing.
|
||||
}
|
||||
|
||||
for _, workers := range workerCounts {
|
||||
builder = pkg.NewBuilder(chain.StateCache(), workers)
|
||||
builder, _ = pkg.NewBuilder(chain.StateCache(), workers)
|
||||
for _, test := range tests {
|
||||
diff, err := builder.BuildStateDiffObject(test.startingArguments, params)
|
||||
if err != nil {
|
||||
@ -1877,7 +1877,7 @@ func TestBuilderWithMovedAccount(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, workers := range workerCounts {
|
||||
builder = pkg.NewBuilder(chain.StateCache(), workers)
|
||||
builder, _ = pkg.NewBuilder(chain.StateCache(), workers)
|
||||
for _, test := range tests {
|
||||
diff, err := builder.BuildStateDiffObject(test.startingArguments, params)
|
||||
if err != nil {
|
||||
@ -1995,7 +1995,7 @@ func TestBuilderWithMovedAccountOnlyLeafs(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, workers := range workerCounts {
|
||||
builder = pkg.NewBuilder(chain.StateCache(), workers)
|
||||
builder, _ = pkg.NewBuilder(chain.StateCache(), workers)
|
||||
for _, test := range tests {
|
||||
diff, err := builder.BuildStateDiffObject(test.startingArguments, params)
|
||||
if err != nil {
|
||||
|
@ -71,9 +71,13 @@ type Service struct {
|
||||
|
||||
// NewStateDiffService creates a new Service
|
||||
func NewStateDiffService(lvlDBReader lvlDBReader, cfg Config) (*Service, error) {
|
||||
builder, err := NewBuilder(lvlDBReader.StateDB(), cfg.Workers)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Service{
|
||||
lvlDBReader: lvlDBReader,
|
||||
Builder: NewBuilder(lvlDBReader.StateDB(), cfg.Workers),
|
||||
Builder: builder,
|
||||
QuitChan: make(chan bool),
|
||||
}, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user