-
Notifications
You must be signed in to change notification settings - Fork 473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NIT-2740] Horizontal Scaling of Validation Node #2354
Open
anodar
wants to merge
30
commits into
master
Choose a base branch
from
sepolia-tooling-merge-redis
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+433
−89
Open
Changes from 13 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
6f0bade
Use redis streams in bold
anodar 2851ef3
Use different streams for bold
anodar d15ef6a
Initialize bold execution runner
anodar 9100a8d
Merge branch 'master' into sepolia-tooling-merge-redis
anodar e2c20ce
Add stream connection and timeout logic
anodar 40b6483
Merge branch 'bold-review' into sepolia-tooling-merge-redis
amsanghi 5d30cc9
Merge branch 'bold-review' into sepolia-tooling-merge-redis
amsanghi 301ea72
fix config
amsanghi 0bbc41e
clean up
amsanghi 3cb9241
Merge branch 'bold-review' into sepolia-tooling-merge-redis
amsanghi b9c8900
remove redudtant changes
amsanghi 8fcd8b7
fix config setup
amsanghi f3fc6f3
Merge branch 'bold-review' into sepolia-tooling-merge-redis
amsanghi ca909c8
Merge branch 'bold-review' into sepolia-tooling-merge-redis
amsanghi f0bc4d4
Update validator/server_arb/redis/consumer.go
amsanghi b421fb0
Update validator/server_arb/redis/consumer.go
amsanghi aeb0e24
Merge branch 'bold-review' into sepolia-tooling-merge-redis
amsanghi 596ff81
Merge branch 'bold-review' into sepolia-tooling-merge-redis
amsanghi 4fbd706
Add tests and fix some bugs
amsanghi 5170a79
Update validator/client/redis/boldproducer.go
rauljordan 545f9d2
add metrics
amsanghi e9e0224
Merge branch 'bold-review' into sepolia-tooling-merge-redis
amsanghi 9be8a33
Merge branch 'bold-review' into sepolia-tooling-merge-redis
amsanghi 161fcca
Merge branch 'bold-review' into sepolia-tooling-merge-redis
amsanghi d895bc4
fix lint
amsanghi 8edfbda
Merge branch 'master' into sepolia-tooling-merge-redis
amsanghi f765a89
fix lint
amsanghi a2cb261
fix lint
amsanghi bc70dfb
fix lint
amsanghi 70f64a1
Merge branch 'master' into sepolia-tooling-merge-redis
eljobe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package redis | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/log" | ||
"github.com/offchainlabs/nitro/pubsub" | ||
"github.com/offchainlabs/nitro/util/containers" | ||
"github.com/offchainlabs/nitro/util/redisutil" | ||
"github.com/offchainlabs/nitro/util/stopwaiter" | ||
"github.com/offchainlabs/nitro/validator/server_api" | ||
) | ||
|
||
// BoldValidationClient implements bold validation client through redis streams. | ||
type BoldValidationClient struct { | ||
stopwaiter.StopWaiter | ||
// producers stores moduleRoot to producer mapping. | ||
producers map[common.Hash]*pubsub.Producer[*server_api.GetLeavesWithStepSizeInput, []common.Hash] | ||
config *ValidationClientConfig | ||
} | ||
|
||
func NewBoldValidationClient(cfg *ValidationClientConfig) (*BoldValidationClient, error) { | ||
return &BoldValidationClient{ | ||
producers: make(map[common.Hash]*pubsub.Producer[*server_api.GetLeavesWithStepSizeInput, []common.Hash]), | ||
config: cfg, | ||
}, nil | ||
} | ||
|
||
func (c *BoldValidationClient) Initialize(ctx context.Context, moduleRoots []common.Hash) error { | ||
if c.config.RedisURL == "" { | ||
return fmt.Errorf("redis url cannot be empty") | ||
} | ||
redisClient, err := redisutil.RedisClientFromURL(c.config.RedisURL) | ||
if err != nil { | ||
return err | ||
} | ||
for _, mr := range moduleRoots { | ||
if c.config.CreateStreams { | ||
if err := pubsub.CreateStream(ctx, server_api.RedisBoldStreamForRoot(c.config.StreamPrefix, mr), redisClient); err != nil { | ||
return fmt.Errorf("creating redis stream: %w", err) | ||
} | ||
} | ||
if _, exists := c.producers[mr]; exists { | ||
log.Warn("Producer already existsw for module root", "hash", mr) | ||
rauljordan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
continue | ||
} | ||
p, err := pubsub.NewProducer[*server_api.GetLeavesWithStepSizeInput, []common.Hash]( | ||
redisClient, server_api.RedisBoldStreamForRoot(c.config.StreamPrefix, mr), &c.config.ProducerConfig) | ||
if err != nil { | ||
log.Warn("failed init redis for %v: %w", mr, err) | ||
continue | ||
} | ||
p.Start(c.GetContext()) | ||
c.producers[mr] = p | ||
} | ||
return nil | ||
} | ||
|
||
func (c *BoldValidationClient) GetLeavesWithStepSize(req *server_api.GetLeavesWithStepSizeInput) containers.PromiseInterface[[]common.Hash] { | ||
producer, found := c.producers[req.ModuleRoot] | ||
if !found { | ||
return containers.NewReadyPromise([]common.Hash{}, fmt.Errorf("no validation is configured for wasm root %v", req.ModuleRoot)) | ||
} | ||
promise, err := producer.Produce(c.GetContext(), req) | ||
if err != nil { | ||
return containers.NewReadyPromise([]common.Hash{}, fmt.Errorf("error producing input: %w", err)) | ||
} | ||
return promise | ||
} | ||
|
||
func (c *BoldValidationClient) Start(ctx_in context.Context) error { | ||
for _, p := range c.producers { | ||
p.Start(ctx_in) | ||
} | ||
c.StopWaiter.Start(ctx_in, c) | ||
return nil | ||
} | ||
|
||
func (c *BoldValidationClient) Stop() { | ||
for _, p := range c.producers { | ||
p.StopAndWait() | ||
} | ||
c.StopWaiter.StopAndWait() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ import ( | |
"github.com/offchainlabs/nitro/util/rpcclient" | ||
"github.com/offchainlabs/nitro/util/stopwaiter" | ||
|
||
"github.com/offchainlabs/nitro/validator/client/redis" | ||
"github.com/offchainlabs/nitro/validator/server_api" | ||
"github.com/offchainlabs/nitro/validator/server_common" | ||
|
||
|
@@ -146,11 +147,21 @@ func (c *ValidationClient) Room() int { | |
|
||
type ExecutionClient struct { | ||
ValidationClient | ||
boldValClient *redis.BoldValidationClient | ||
} | ||
|
||
func NewExecutionClient(config rpcclient.ClientConfigFetcher, stack *node.Node) *ExecutionClient { | ||
func NewExecutionClient(config rpcclient.ClientConfigFetcher, redisBoldValidationClientConfig *redis.ValidationClientConfig, stack *node.Node) *ExecutionClient { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. boldValclient does not need to be a field of executionclient, they are separate beings. |
||
var boldClient *redis.BoldValidationClient | ||
if redisBoldValidationClientConfig != nil && redisBoldValidationClientConfig.Enabled() { | ||
var err error | ||
boldClient, err = redis.NewBoldValidationClient(redisBoldValidationClientConfig) | ||
if err != nil { | ||
log.Error("Creating new redis bold validation client", "error", err) | ||
} | ||
} | ||
return &ExecutionClient{ | ||
ValidationClient: *NewValidationClient(config, stack), | ||
boldValClient: boldClient, | ||
} | ||
} | ||
|
||
|
@@ -172,8 +183,10 @@ func (c *ExecutionClient) CreateExecutionRun(wasmModuleRoot common.Hash, input * | |
|
||
type ExecutionClientRun struct { | ||
stopwaiter.StopWaiter | ||
client *ExecutionClient | ||
id uint64 | ||
client *ExecutionClient | ||
id uint64 | ||
wasmModuleRoot common.Hash | ||
input *validator.ValidationInput | ||
} | ||
|
||
func (c *ExecutionClient) LatestWasmModuleRoot() containers.PromiseInterface[common.Hash] { | ||
|
@@ -233,6 +246,15 @@ func (r *ExecutionClientRun) GetStepAt(pos uint64) containers.PromiseInterface[* | |
} | ||
|
||
func (r *ExecutionClientRun) GetMachineHashesWithStepSize(machineStartIndex, stepSize, maxIterations uint64) containers.PromiseInterface[[]common.Hash] { | ||
if r.client.boldValClient != nil { | ||
return r.client.boldValClient.GetLeavesWithStepSize(&server_api.GetLeavesWithStepSizeInput{ | ||
anodar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ModuleRoot: r.wasmModuleRoot, | ||
MachineStartIndex: machineStartIndex, | ||
StepSize: stepSize, | ||
NumDesiredLeaves: maxIterations, | ||
ValidationInput: r.input, | ||
}) | ||
} | ||
return stopwaiter.LaunchPromiseThread[[]common.Hash](r, func(ctx context.Context) ([]common.Hash, error) { | ||
var resJson []common.Hash | ||
err := r.client.client.CallContext(ctx, &resJson, server_api.Namespace+"_getMachineHashesWithStepSize", r.id, machineStartIndex, stepSize, maxIterations) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need a separate one for BOLD or could we use the same one?