-
Notifications
You must be signed in to change notification settings - Fork 38
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
Testnets: grant sequencer enclaveID permission on L1 #2185
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bcaf1d1
Testnets: grant sequencer enclaveID permission on L1
BedrockSquirrel 4752c25
wait for node up before permissioning
BedrockSquirrel 5b4a4ea
permission step needs build step for its output
BedrockSquirrel 46894db
Fix hardcoded values in wiring
BedrockSquirrel a9deb2f
fix rpc port
BedrockSquirrel 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
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 |
---|---|---|
@@ -1,9 +1,18 @@ | ||
package l1grantsequencers | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"io" | ||
"strings" | ||
"time" | ||
|
||
"github.com/docker/docker/api/types" | ||
"github.com/docker/docker/client" | ||
"github.com/ten-protocol/go-ten/go/common/docker" | ||
"github.com/ten-protocol/go-ten/go/obsclient" | ||
"github.com/ten-protocol/go-ten/go/rpc" | ||
) | ||
|
||
type GrantSequencers struct { | ||
|
@@ -18,14 +27,26 @@ func NewGrantSequencers(cfg *Config) (*GrantSequencers, error) { | |
} | ||
|
||
func (s *GrantSequencers) Start() error { | ||
fmt.Printf("Starting grant sequencers with config: %s\n", s.cfg) | ||
var enclaveIDs string | ||
var err error | ||
if s.cfg.enclaveIDs != "" { | ||
enclaveIDs = s.cfg.enclaveIDs | ||
} else if s.cfg.sequencerURL != "" { | ||
enclaveIDs, err = fetchEnclaveIDs(s.cfg.sequencerURL) | ||
if err != nil { | ||
return err | ||
} | ||
} else { | ||
return fmt.Errorf("enclaveIDs or sequencerURL must be provided") | ||
} | ||
cmds := []string{ | ||
"npx", | ||
"hardhat", | ||
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. This script didn't seem to be running properly, it needed the hardhat command to use the --network flag and I couldn't get it to work with positional args so changed them to env vars. |
||
"run", | ||
"--network", | ||
"layer1", | ||
"scripts/sequencer/001_grant_sequencers.ts", | ||
s.cfg.mgmtContractAddress, | ||
s.cfg.enclaveIDs, | ||
} | ||
|
||
envs := map[string]string{ | ||
|
@@ -37,8 +58,12 @@ func (s *GrantSequencers) Start() error { | |
"accounts": [ "%s" ] | ||
} | ||
}`, s.cfg.l1HTTPURL, s.cfg.privateKey), | ||
"MGMT_CONTRACT_ADDRESS": s.cfg.mgmtContractAddress, | ||
"ENCLAVE_IDS": enclaveIDs, | ||
} | ||
|
||
fmt.Printf("Starting grant sequencer script. MgntContractAddress: %s, EnclaveIDs: %s\n", s.cfg.mgmtContractAddress, enclaveIDs) | ||
|
||
containerID, err := docker.StartNewContainer( | ||
"grant-sequencers", | ||
s.cfg.dockerImage, | ||
|
@@ -55,3 +80,67 @@ func (s *GrantSequencers) Start() error { | |
s.containerID = containerID | ||
return nil | ||
} | ||
|
||
func (s *GrantSequencers) WaitForFinish() error { | ||
cli, err := client.NewClientWithOpts(client.FromEnv) | ||
if err != nil { | ||
return fmt.Errorf("failed to create docker client: %w", err) | ||
} | ||
defer cli.Close() | ||
|
||
// make sure the container has finished execution | ||
err = docker.WaitForContainerToFinish(s.containerID, 15*time.Minute) | ||
if err != nil { | ||
fmt.Println("Error waiting for container to finish: ", err) | ||
s.PrintLogs(cli) | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func fetchEnclaveIDs(url string) (string, error) { | ||
// fetch enclaveIDs | ||
client, err := rpc.NewNetworkClient(url) | ||
if err != nil { | ||
return "", fmt.Errorf("failed to create network client (%s): %w", url, err) | ||
} | ||
defer client.Stop() | ||
|
||
obsClient := obsclient.NewObsClient(client) | ||
health, err := obsClient.Health() | ||
if err != nil { | ||
return "", fmt.Errorf("failed to get health status: %w", err) | ||
} | ||
|
||
if len(health.Enclaves) == 0 { | ||
return "", fmt.Errorf("could not retrieve enclave IDs from health endpoint - no enclaves found") | ||
} | ||
|
||
var enclaveIDs []string | ||
for _, status := range health.Enclaves { | ||
enclaveIDs = append(enclaveIDs, status.EnclaveID.String()) | ||
} | ||
return strings.Join(enclaveIDs, ","), nil | ||
} | ||
|
||
func (s *GrantSequencers) PrintLogs(cli *client.Client) { | ||
logsOptions := types.ContainerLogsOptions{ | ||
ShowStdout: true, | ||
ShowStderr: true, | ||
} | ||
|
||
// Read the container logs | ||
out, err := cli.ContainerLogs(context.Background(), s.containerID, logsOptions) | ||
if err != nil { | ||
fmt.Printf("Error printing out container %s logs... %v\n", s.containerID, err) | ||
} | ||
defer out.Close() | ||
|
||
var buf bytes.Buffer | ||
_, err = io.Copy(&buf, out) | ||
if err != nil { | ||
fmt.Printf("Error getting logs for container %s\n", s.containerID) | ||
} | ||
fmt.Println(buf.String()) | ||
} |
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.
Sequencer needs to be permissioned before L2 contracts can be deployed.