Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/ten-protocol/go-ten into wi…
Browse files Browse the repository at this point in the history
…ll/upgrade-geth
  • Loading branch information
badgersrus committed Aug 7, 2024
2 parents 402ef86 + 475b705 commit 4cb1129
Show file tree
Hide file tree
Showing 30 changed files with 125 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const topic = hre.ethers.id(eventSignature)

// Get the interface for the event in order to convert it to cross chain message.
let eventIface = new hre.ethers.Interface([ `event LogMessagePublished(address indexed,uint64,uint32,uint32,bytes,uint8)`]);
let eventIface = new hre.ethers.Interface([ `event LogMessagePublished(address,uint64,uint32,uint32,bytes,uint8)`]);

// This function converts the logs from transaction receipts into cross chain messages
function getXChainMessages(result: Receipt) {
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/generated/EthereumBridge/EthereumBridge.go

Large diffs are not rendered by default.

Large diffs are not rendered by default.

28 changes: 9 additions & 19 deletions contracts/generated/MerkleTreeMessageBus/MerkleTreeMessageBus.go

Large diffs are not rendered by default.

28 changes: 9 additions & 19 deletions contracts/generated/MessageBus/MessageBus.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/generated/ObsERC20/ObsERC20.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/generated/ObscuroBridge/ObscuroBridge.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/generated/WrappedERC20/WrappedERC20.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/src/messaging/IMessageBus.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface IMessageBus {
// The enclave listens for it on the deployed message bus addresses.
event LogMessagePublished
(
address indexed sender,
address sender,
uint64 sequence,
uint32 nonce,
uint32 topic,
Expand Down
4 changes: 2 additions & 2 deletions contracts/test/bridge-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe("Bridge", function () {

const eventSignature = "LogMessagePublished(address,uint64,uint32,uint32,bytes,uint8)";
const topic = ethers.id(eventSignature)
let eventIface = new ethers.Interface([ `event LogMessagePublished(address indexed,uint64,uint32,uint32,bytes,uint8)`]);
let eventIface = new ethers.Interface([ `event LogMessagePublished(address,uint64,uint32,uint32,bytes,uint8)`]);

const receipt = (await tx.wait())!!;

Expand Down Expand Up @@ -283,7 +283,7 @@ describe("Bridge", function () {

await expect(event).to.not.be.undefined;

let eventIface = new ethers.Interface([ `event LogMessagePublished(address indexed,uint64,uint32,uint32,bytes,uint8)`]);
let eventIface = new ethers.Interface([ `event LogMessagePublished(address,uint64,uint32,uint32,bytes,uint8)`]);

const decodedEvent = eventIface.parseLog({
topics: event!.topics!.map((v)=>v),
Expand Down
36 changes: 21 additions & 15 deletions go/common/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (

const _networkName = "node_network"

// volumes is a map from volume name to dir name it will have within the container. If a volume doesn't exist this will create it.
func StartNewContainer(containerName, image string, cmds []string, ports []int, envs, devices, volumes map[string]string) (string, error) {
// StartNewContainer - volumes is a map from volume name to dir name it will have within the container. If a volume doesn't exist this will create it.
func StartNewContainer(containerName, image string, cmds []string, ports []int, envs, devices, volumes map[string]string, autoRestart bool) (string, error) {
ctx := context.Background()
cli, err := client.NewClientWithOpts(client.FromEnv)
if err != nil {
Expand Down Expand Up @@ -95,21 +95,27 @@ func StartNewContainer(containerName, image string, cmds []string, ports []int,
"max-file": "3",
}

hc := container.HostConfig{
PortBindings: portBindings,
Mounts: mountVolumes,
Resources: container.Resources{Devices: deviceMapping},
LogConfig: container.LogConfig{Type: "json-file", Config: logOptions},
}

if autoRestart {
hc.RestartPolicy = container.RestartPolicy{Name: "unless-stopped"}
}

// create the container
resp, err := cli.ContainerCreate(ctx, &container.Config{
Image: image,
Entrypoint: cmds,
Tty: false,
ExposedPorts: exposedPorts,
Env: envVars,
},
&container.HostConfig{
PortBindings: portBindings,
Mounts: mountVolumes,
RestartPolicy: container.RestartPolicy{Name: "unless-stopped"},
Resources: container.Resources{Devices: deviceMapping},
LogConfig: container.LogConfig{Type: "json-file", Config: logOptions},
resp, err := cli.ContainerCreate(ctx,
&container.Config{
Image: image,
Entrypoint: cmds,
Tty: false,
ExposedPorts: exposedPorts,
Env: envVars,
},
&hc,
&network.NetworkingConfig{
EndpointsConfig: map[string]*network.EndpointSettings{
_networkName: {
Expand Down
2 changes: 1 addition & 1 deletion go/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ type (
// To work properly, all of the receipts are required, due to rlp encoding pruning some of the information.
// The receipts must also be in the correct order.
type BlockAndReceipts struct {
Block *types.Block
Block *L1Block
ReceiptsMap map[int]*types.Receipt // sparse map with obscuro-relevant receipts in it
Receipts *types.Receipts
successfulTransactions *types.Transactions
Expand Down
5 changes: 0 additions & 5 deletions go/enclave/crosschain/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,11 @@ func convertLogsToMessages(logs []types.Log, eventName string, messageBusABI abi
messages := make(common.CrossChainMessages, 0)

for _, log := range logs {
if len(log.Topics) != 2 {
return nil, fmt.Errorf("invalid number of topics in log: %d", len(log.Topics))
}

var event MessageBus.MessageBusLogMessagePublished
err := messageBusABI.UnpackIntoInterface(&event, eventName, log.Data)
if err != nil {
return nil, err
}
event.Sender = gethcommon.BytesToAddress(log.Topics[1].Bytes())

msg := createCrossChainMessage(event)
messages = append(messages, msg)
Expand Down
3 changes: 1 addition & 2 deletions go/enclave/nodetype/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package nodetype
import (
"context"

"github.com/ethereum/go-ethereum/core/types"
"github.com/ten-protocol/go-ten/go/common"
"github.com/ten-protocol/go-ten/go/enclave/components"
"github.com/ten-protocol/go-ten/go/enclave/core"
Expand All @@ -21,7 +20,7 @@ type NodeType interface {
OnL1Fork(ctx context.Context, fork *common.ChainFork) error

// OnL1Block - performed after the block was processed
OnL1Block(ctx context.Context, block *types.Block, result *components.BlockIngestionType) error
OnL1Block(ctx context.Context, block *common.L1Block, result *components.BlockIngestionType) error

ExportCrossChainData(context.Context, uint64, uint64) (*common.ExtCrossChainBundle, error)

Expand Down
2 changes: 1 addition & 1 deletion go/enclave/nodetype/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ func (s *sequencer) signCrossChainBundle(bundle *common.ExtCrossChainBundle) err
return nil
}

func (s *sequencer) OnL1Block(ctx context.Context, block *types.Block, result *components.BlockIngestionType) error {
func (s *sequencer) OnL1Block(ctx context.Context, _ *common.L1Block, result *components.BlockIngestionType) error {
// nothing to do
return nil
}
Expand Down
4 changes: 1 addition & 3 deletions go/enclave/nodetype/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"github.com/ten-protocol/go-ten/go/enclave/crypto"
"github.com/ten-protocol/go-ten/go/enclave/txpool"

"github.com/ethereum/go-ethereum/core/types"

"github.com/ten-protocol/go-ten/go/common/errutil"
"github.com/ten-protocol/go-ten/go/common/log"
"github.com/ten-protocol/go-ten/go/common/signature"
Expand Down Expand Up @@ -187,7 +185,7 @@ func (val *obsValidator) handleGenesis(ctx context.Context, batch *common.BatchH
return nil
}

func (val *obsValidator) OnL1Block(ctx context.Context, block *types.Block, result *components.BlockIngestionType) error {
func (val *obsValidator) OnL1Block(ctx context.Context, _ *common.L1Block, result *components.BlockIngestionType) error {
return val.ExecuteStoredBatches(ctx)
}

Expand Down
9 changes: 9 additions & 0 deletions go/host/enclave/guardian.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,15 @@ func (g *Guardian) submitL1Block(block *common.L1Block, isLatest bool) (bool, er
g.submitDataLock.Unlock() // lock must be released before returning
return false, fmt.Errorf("could not fetch obscuro receipts for block=%s - %w", block.Hash(), err)
}
// only submit the relevant transactions to the enclave
// nullify all non-relevant transactions
txs := block.Transactions()
for i, rec := range receipts {
if rec == nil {
txs[i] = nil
}
}

resp, err := g.enclaveClient.SubmitL1Block(context.Background(), block, receipts, isLatest)
g.submitDataLock.Unlock() // lock is only guarding the enclave call, so we can release it now
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion go/host/l1/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ func (p *Publisher) PublishCrossChainBundle(bundle *common.ExtCrossChainBundle,
tx, err := managementCtr.AddCrossChainMessagesRoot(transactor, [32]byte(bundle.LastBatchHash.Bytes()), bundle.L1BlockHash, bundle.L1BlockNum, bundle.CrossChainRootHashes, bundle.Signature, rollupNum, forkID)
if err != nil {
if !errors.Is(err, errutil.ErrCrossChainBundleRepublished) {
p.logger.Error("Error with submitting cross chain bundle transaction.", log.ErrKey, err, log.BundleHashKey, bundle.LastBatchHash)
p.logger.Info("Cross chain bundle already published. Proceeding without publishing", log.ErrKey, err, log.BundleHashKey, bundle.LastBatchHash)
return nil
}
p.hostWallet.SetNonce(p.hostWallet.GetNonce() - 1)
return fmt.Errorf("unable to submit cross chain bundle transaction. Cause: %w", err)
Expand Down
6 changes: 3 additions & 3 deletions go/node/docker_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (d *DockerNode) startHost() error {
d.cfg.hostP2PPort,
}

_, err := docker.StartNewContainer(d.cfg.nodeName+"-host", d.cfg.hostImage, cmd, exposedPorts, nil, nil, nil)
_, err := docker.StartNewContainer(d.cfg.nodeName+"-host", d.cfg.hostImage, cmd, exposedPorts, nil, nil, nil, true)

return err
}
Expand Down Expand Up @@ -195,7 +195,7 @@ func (d *DockerNode) startEnclave() error {

// we need the enclave volume to store the db credentials
enclaveVolume := map[string]string{d.cfg.nodeName + "-enclave-volume": _enclaveDataDir}
_, err := docker.StartNewContainer(d.cfg.nodeName+"-enclave", d.cfg.enclaveImage, cmd, exposedPorts, envs, devices, enclaveVolume)
_, err := docker.StartNewContainer(d.cfg.nodeName+"-enclave", d.cfg.enclaveImage, cmd, exposedPorts, envs, devices, enclaveVolume, true)

return err
}
Expand All @@ -222,7 +222,7 @@ func (d *DockerNode) startEdgelessDB() error {
//dbVolume := map[string]string{d.cfg.nodeName + "-db-volume": "/data"}
//_, err := docker.StartNewContainer(d.cfg.nodeName+"-edgelessdb", d.cfg.edgelessDBImage, nil, nil, envs, devices, dbVolume)

_, err := docker.StartNewContainer(d.cfg.nodeName+"-edgelessdb", d.cfg.edgelessDBImage, nil, nil, envs, devices, nil)
_, err := docker.StartNewContainer(d.cfg.nodeName+"-edgelessdb", d.cfg.edgelessDBImage, nil, nil, envs, devices, nil, true)

return err
}
1 change: 1 addition & 0 deletions testnet/launcher/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ func (t *Testnet) Start() error {
gateway.WithTenNodeHTTPPort(13010),
gateway.WithTenNodeWSPort(13011),
gateway.WithTenNodeHost("validator-host"),
gateway.WithRateLimitUserComputeTime(0), // disable rate limiting for local network
gateway.WithDockerImage("testnetobscuronet.azurecr.io/obscuronet/obscuro_gateway:latest"),
),
)
Expand Down
2 changes: 1 addition & 1 deletion testnet/launcher/eth2network/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (n *Eth2Network) Start() error {
// keep a volume of binaries to avoid downloading
volume := map[string]string{"eth2_bin": "/home/obscuro/go-obscuro/integration/.build/eth2_bin/"}

_, err := docker.StartNewContainer("eth2network", "testnetobscuronet.azurecr.io/obscuronet/eth2network:latest", cmds, exposedPorts, nil, nil, volume)
_, err := docker.StartNewContainer("eth2network", "testnetobscuronet.azurecr.io/obscuronet/eth2network:latest", cmds, exposedPorts, nil, nil, volume, false)
return err
}

Expand Down
2 changes: 1 addition & 1 deletion testnet/launcher/faucet/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (n *DockerFaucet) Start() error {
"--serverPort", fmt.Sprintf("%d", n.cfg.faucetPort),
}

_, err := docker.StartNewContainer("faucet", n.cfg.dockerImage, cmds, []int{n.cfg.faucetPort}, nil, nil, nil)
_, err := docker.StartNewContainer("faucet", n.cfg.dockerImage, cmds, []int{n.cfg.faucetPort}, nil, nil, nil, false)
return err
}

Expand Down
2 changes: 1 addition & 1 deletion testnet/launcher/fundsrecovery/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (n *FundsRecovery) Start() error {
`, n.cfg.l1HTTPURL, n.cfg.l1privateKey),
}

containerID, err := docker.StartNewContainer("recover-funds", n.cfg.dockerImage, cmds, nil, envs, nil, nil)
containerID, err := docker.StartNewContainer("recover-funds", n.cfg.dockerImage, cmds, nil, envs, nil, nil, false)
if err != nil {
return err
}
Expand Down
21 changes: 15 additions & 6 deletions testnet/launcher/gateway/config.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package gateway

import "time"

// Option is a function that applies configs to a Config Object
type Option = func(c *Config)

// Config holds the properties that configure the package
type Config struct {
tenNodeHost string
tenNodeHTTPPort int
tenNodeWSPort int
gatewayHTTPPort int
gatewayWSPort int
dockerImage string
tenNodeHost string
tenNodeHTTPPort int
tenNodeWSPort int
gatewayHTTPPort int
gatewayWSPort int
rateLimitUserComputeTime time.Duration
dockerImage string
}

func NewGatewayConfig(opts ...Option) *Config {
Expand Down Expand Up @@ -58,3 +61,9 @@ func WithGatewayWSPort(i int) Option {
c.gatewayWSPort = i
}
}

func WithRateLimitUserComputeTime(d time.Duration) Option {
return func(c *Config) {
c.rateLimitUserComputeTime = d
}
}
3 changes: 2 additions & 1 deletion testnet/launcher/gateway/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ func (n *DockerGateway) Start() error {
"--nodeHost", n.cfg.tenNodeHost,
"--dbType", "sqlite",
"--logPath", "sys_out",
"--rateLimitUserComputeTime", fmt.Sprintf("%d", n.cfg.rateLimitUserComputeTime),
}

_, err := docker.StartNewContainer("gateway", n.cfg.dockerImage, cmds, []int{n.cfg.gatewayHTTPPort, n.cfg.gatewayWSPort}, nil, nil, nil)
_, err := docker.StartNewContainer("gateway", n.cfg.dockerImage, cmds, []int{n.cfg.gatewayHTTPPort, n.cfg.gatewayWSPort}, nil, nil, nil, true)
return err
}

Expand Down
2 changes: 1 addition & 1 deletion testnet/launcher/l1contractdeployer/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (n *ContractDeployer) Start() error {
`, n.cfg.l1HTTPURL, n.cfg.privateKey),
}

containerID, err := docker.StartNewContainer("hh-l1-deployer", n.cfg.dockerImage, cmds, ports, envs, nil, nil)
containerID, err := docker.StartNewContainer("hh-l1-deployer", n.cfg.dockerImage, cmds, ports, envs, nil, nil, false)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion testnet/launcher/l2contractdeployer/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (n *ContractDeployer) Start() error {
`, n.cfg.l1HTTPURL, n.cfg.l1privateKey, n.cfg.l2PrivateKey, n.cfg.hocPKString, n.cfg.pocPKString),
}

containerID, err := docker.StartNewContainer("hh-l2-deployer", n.cfg.dockerImage, cmds, ports, envs, nil, nil)
containerID, err := docker.StartNewContainer("hh-l2-deployer", n.cfg.dockerImage, cmds, ports, envs, nil, nil, false)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 4cb1129

Please sign in to comment.