Skip to content

Commit

Permalink
Merge pull request #1014 from statechannels/proper-chain-id
Browse files Browse the repository at this point in the history
Engine now gets chain id from chain service
  • Loading branch information
lalexgap authored Dec 7, 2022
2 parents 5d8bdf0 + 937ae7d commit eafac67
Show file tree
Hide file tree
Showing 30 changed files with 143 additions and 61 deletions.
2 changes: 1 addition & 1 deletion channel/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func TestSerde(t *testing.T) {
latestSupportedStateTurnNum: 2,
}

someChannelJSON := `{"Id":"0x0100000000000000000000000000000000000000000000000000000000000000","MyIndex":1,"OnChainFunding":null,"ChainId":9001,"Participants":["0xf5a1bb5607c9d079e46d1b3dc33f257d937b43bd","0x760bf27cd45036a6c486802d30b5d90cffbe31fe"],"ChannelNonce":37140676580,"AppDefinition":"0x5e29e5ab8ef33f050c7cc10b5a0456d975c5f88d","ChallengeDuration":60,"SignedStateForTurnNum":{"0":{"State":{"ChainId":9001,"Participants":["0xf5a1bb5607c9d079e46d1b3dc33f257d937b43bd","0x760bf27cd45036a6c486802d30b5d90cffbe31fe"],"ChannelNonce":37140676580,"AppDefinition":"0x5e29e5ab8ef33f050c7cc10b5a0456d975c5f88d","ChallengeDuration":60,"AppData":"","Outcome":[{"Asset":"0x0000000000000000000000000000000000000000","Metadata":null,"Allocations":[{"Destination":"0x000000000000000000000000f5a1bb5607c9d079e46d1b3dc33f257d937b43bd","Amount":5,"AllocationType":0,"Metadata":null},{"Destination":"0x000000000000000000000000ee18ff1575055691009aa246ae608132c57a422c","Amount":5,"AllocationType":0,"Metadata":null}]}],"TurnNum":5,"IsFinal":false},"Sigs":{}}},"LatestSupportedStateTurnNum":2}`
someChannelJSON := `{"Id":"0x0100000000000000000000000000000000000000000000000000000000000000","MyIndex":1,"OnChainFunding":null,"ChainId":1337,"Participants":["0xf5a1bb5607c9d079e46d1b3dc33f257d937b43bd","0x760bf27cd45036a6c486802d30b5d90cffbe31fe"],"ChannelNonce":37140676580,"AppDefinition":"0x5e29e5ab8ef33f050c7cc10b5a0456d975c5f88d","ChallengeDuration":60,"SignedStateForTurnNum":{"0":{"State":{"ChainId":1337,"Participants":["0xf5a1bb5607c9d079e46d1b3dc33f257d937b43bd","0x760bf27cd45036a6c486802d30b5d90cffbe31fe"],"ChannelNonce":37140676580,"AppDefinition":"0x5e29e5ab8ef33f050c7cc10b5a0456d975c5f88d","ChallengeDuration":60,"AppData":"","Outcome":[{"Asset":"0x0000000000000000000000000000000000000000","Metadata":null,"Allocations":[{"Destination":"0x000000000000000000000000f5a1bb5607c9d079e46d1b3dc33f257d937b43bd","Amount":5,"AllocationType":0,"Metadata":null},{"Destination":"0x000000000000000000000000ee18ff1575055691009aa246ae608132c57a422c","Amount":5,"AllocationType":0,"Metadata":null}]}],"TurnNum":5,"IsFinal":false},"Sigs":{}}},"LatestSupportedStateTurnNum":2}`

// Marshalling
got, err := json.Marshal(someChannel)
Expand Down
4 changes: 3 additions & 1 deletion channel/consensus_channel/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/statechannels/go-nitro/types"
)

const TEST_CHAIN_ID = 1337

var channel1Id = types.Destination{1}
var targetChannel = types.Destination{2}

Expand All @@ -23,7 +25,7 @@ func fp() state.FixedPart {
}
return state.FixedPart{
Participants: participants[:],
ChainId: big.NewInt(9001),
ChainId: big.NewInt(1337),
ChannelNonce: 9001,
ChallengeDuration: 100,
}
Expand Down
2 changes: 1 addition & 1 deletion channel/consensus_channel/serde_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestSerde(t *testing.T) {
},
},
}
someConsensusChannelJSON := `{"Id":"0x0100000000000000000000000000000000000000000000000000000000000000","OnChainFunding":{"0x0000000000000000000000000000000000000000":9},"MyIndex":0,"FP":{"ChainId":9001,"Participants":["0xaaa6628ec44a8a742987ef3a114ddfe2d4f7adce","0xbbb676f9cff8d242e9eac39d063848807d3d1d94"],"ChannelNonce":9001,"AppDefinition":"0x0000000000000000000000000000000000000000","ChallengeDuration":100},"Current":{"TurnNum":0,"Outcome":{"AssetAddress":"0x0000000000000000000000000000000000000000","Leader":{"Destination":"0x000000000000000000000000aaa6628ec44a8a742987ef3a114ddfe2d4f7adce","Amount":2},"Follower":{"Destination":"0x000000000000000000000000bbb676f9cff8d242e9eac39d063848807d3d1d94","Amount":7},"Guarantees":{"0x6300000000000000000000000000000000000000000000000000000000000000":{"Amount":1,"Target":"0x6300000000000000000000000000000000000000000000000000000000000000","Left":"0x000000000000000000000000aaa6628ec44a8a742987ef3a114ddfe2d4f7adce","Right":"0x000000000000000000000000aaa6628ec44a8a742987ef3a114ddfe2d4f7adce"}}},"Signatures":[{"R":"cEs6/MbnAhAsoa8/c887N/MAfzaMQOi4HKgjpldAoFM=","S":"FAQK1MWY27BVpQQwFCoTUY4TMLedJO7Yb8vf8aepVYk=","V":0},{"R":"FAQK1MWY27BVpQQwFCoTUY4TMLedJO7Yb8vf8aepVYk=","S":"cEs6/MbnAhAsoa8/c887N/MAfzaMQOi4HKgjpldAoFM=","V":0}]},"ProposalQueue":[{"R":"FAQK1MWY27BVpQQwFCoTUY4TMLedJO7Yb8vf8aepVYk=","S":"cEs6/MbnAhAsoa8/c887N/MAfzaMQOi4HKgjpldAoFM=","V":0,"Proposal":{"LedgerID":"0x0000000000000000000000000000000000000000000000000000000000000000","ToAdd":{"Guarantee":{"Amount":1,"Target":"0x0300000000000000000000000000000000000000000000000000000000000000","Left":"0x000000000000000000000000aaa6628ec44a8a742987ef3a114ddfe2d4f7adce","Right":"0x000000000000000000000000bbb676f9cff8d242e9eac39d063848807d3d1d94"},"LeftDeposit":1},"ToRemove":{"Target":"0x0000000000000000000000000000000000000000000000000000000000000000","LeftAmount":null}},"TurnNum":0},{"R":"FAQK1MWY27BVpQQwFCoTUY4TMLedJO7Yb8vf8aepVYk=","S":"cEs6/MbnAhAsoa8/c887N/MAfzaMQOi4HKgjpldAoFM=","V":0,"Proposal":{"LedgerID":"0x0000000000000000000000000000000000000000000000000000000000000000","ToAdd":{"Guarantee":{"Amount":null,"Target":"0x0000000000000000000000000000000000000000000000000000000000000000","Left":"0x0000000000000000000000000000000000000000000000000000000000000000","Right":"0x0000000000000000000000000000000000000000000000000000000000000000"},"LeftDeposit":null},"ToRemove":{"Target":"0x0300000000000000000000000000000000000000000000000000000000000000","LeftAmount":1}},"TurnNum":0}]}`
someConsensusChannelJSON := `{"Id":"0x0100000000000000000000000000000000000000000000000000000000000000","OnChainFunding":{"0x0000000000000000000000000000000000000000":9},"MyIndex":0,"FP":{"ChainId":1337,"Participants":["0xaaa6628ec44a8a742987ef3a114ddfe2d4f7adce","0xbbb676f9cff8d242e9eac39d063848807d3d1d94"],"ChannelNonce":9001,"AppDefinition":"0x0000000000000000000000000000000000000000","ChallengeDuration":100},"Current":{"TurnNum":0,"Outcome":{"AssetAddress":"0x0000000000000000000000000000000000000000","Leader":{"Destination":"0x000000000000000000000000aaa6628ec44a8a742987ef3a114ddfe2d4f7adce","Amount":2},"Follower":{"Destination":"0x000000000000000000000000bbb676f9cff8d242e9eac39d063848807d3d1d94","Amount":7},"Guarantees":{"0x6300000000000000000000000000000000000000000000000000000000000000":{"Amount":1,"Target":"0x6300000000000000000000000000000000000000000000000000000000000000","Left":"0x000000000000000000000000aaa6628ec44a8a742987ef3a114ddfe2d4f7adce","Right":"0x000000000000000000000000aaa6628ec44a8a742987ef3a114ddfe2d4f7adce"}}},"Signatures":[{"R":"cEs6/MbnAhAsoa8/c887N/MAfzaMQOi4HKgjpldAoFM=","S":"FAQK1MWY27BVpQQwFCoTUY4TMLedJO7Yb8vf8aepVYk=","V":0},{"R":"FAQK1MWY27BVpQQwFCoTUY4TMLedJO7Yb8vf8aepVYk=","S":"cEs6/MbnAhAsoa8/c887N/MAfzaMQOi4HKgjpldAoFM=","V":0}]},"ProposalQueue":[{"R":"FAQK1MWY27BVpQQwFCoTUY4TMLedJO7Yb8vf8aepVYk=","S":"cEs6/MbnAhAsoa8/c887N/MAfzaMQOi4HKgjpldAoFM=","V":0,"Proposal":{"LedgerID":"0x0000000000000000000000000000000000000000000000000000000000000000","ToAdd":{"Guarantee":{"Amount":1,"Target":"0x0300000000000000000000000000000000000000000000000000000000000000","Left":"0x000000000000000000000000aaa6628ec44a8a742987ef3a114ddfe2d4f7adce","Right":"0x000000000000000000000000bbb676f9cff8d242e9eac39d063848807d3d1d94"},"LeftDeposit":1},"ToRemove":{"Target":"0x0000000000000000000000000000000000000000000000000000000000000000","LeftAmount":null}},"TurnNum":0},{"R":"FAQK1MWY27BVpQQwFCoTUY4TMLedJO7Yb8vf8aepVYk=","S":"cEs6/MbnAhAsoa8/c887N/MAfzaMQOi4HKgjpldAoFM=","V":0,"Proposal":{"LedgerID":"0x0000000000000000000000000000000000000000000000000000000000000000","ToAdd":{"Guarantee":{"Amount":null,"Target":"0x0000000000000000000000000000000000000000000000000000000000000000","Left":"0x0000000000000000000000000000000000000000000000000000000000000000","Right":"0x0000000000000000000000000000000000000000000000000000000000000000"},"LeftDeposit":null},"ToRemove":{"Target":"0x0300000000000000000000000000000000000000000000000000000000000000","LeftAmount":1}},"TurnNum":0}]}`

type testCase struct {
name string
Expand Down
2 changes: 1 addition & 1 deletion channel/state/signedstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestJSON(t *testing.T) {
sigA, _ := TestState.Sign(common.Hex2Bytes(`caab404f975b4620747174a75f08d98b4e5a7053b691b41bcfc0d839d48b7634`))
_ = ss1.AddSignature(sigA)

msgString := `{"State":{"ChainId":9001,"Participants":["0xf5a1bb5607c9d079e46d1b3dc33f257d937b43bd","0x760bf27cd45036a6c486802d30b5d90cffbe31fe"],"ChannelNonce":37140676580,"AppDefinition":"0x5e29e5ab8ef33f050c7cc10b5a0456d975c5f88d","ChallengeDuration":60,"AppData":"","Outcome":[{"Asset":"0x0000000000000000000000000000000000000000","Metadata":null,"Allocations":[{"Destination":"0x000000000000000000000000f5a1bb5607c9d079e46d1b3dc33f257d937b43bd","Amount":5,"AllocationType":0,"Metadata":null},{"Destination":"0x000000000000000000000000ee18ff1575055691009aa246ae608132c57a422c","Amount":5,"AllocationType":0,"Metadata":null}]}],"TurnNum":5,"IsFinal":false},"Sigs":{"0":{"R":"cEs6/MbnAhAsoa8/c887N/MAfzaMQOi4HKgjpldAoFM=","S":"FAQK1MWY27BVpQQwFCoTUY4TMLedJO7Yb8vf8aepVYk=","V":27}}}`
msgString := `{"State":{"ChainId":1337,"Participants":["0xf5a1bb5607c9d079e46d1b3dc33f257d937b43bd","0x760bf27cd45036a6c486802d30b5d90cffbe31fe"],"ChannelNonce":37140676580,"AppDefinition":"0x5e29e5ab8ef33f050c7cc10b5a0456d975c5f88d","ChallengeDuration":60,"AppData":"","Outcome":[{"Asset":"0x0000000000000000000000000000000000000000","Metadata":null,"Allocations":[{"Destination":"0x000000000000000000000000f5a1bb5607c9d079e46d1b3dc33f257d937b43bd","Amount":5,"AllocationType":0,"Metadata":null},{"Destination":"0x000000000000000000000000ee18ff1575055691009aa246ae608132c57a422c","Amount":5,"AllocationType":0,"Metadata":null}]}],"TurnNum":5,"IsFinal":false},"Sigs":{"0":{"R":"vi0nrgiS4pgbMeAXyMtvmbwMzRrn0bBvxp8TEfYcPgE=","S":"IUIFYsgiejqjuOFVdPk/pitk9CmucnV43O6jf2CDdC4=","V":27}}}`

t.Run(`TestMarshalJSON`, func(t *testing.T) {
got, err := ss1.MarshalJSON()
Expand Down
13 changes: 7 additions & 6 deletions channel/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package state

import (
"bytes"
"fmt"
"math/big"
"testing"

Expand All @@ -11,13 +12,13 @@ import (
)

// The following constants are generated from our ts nitro-protocol package
var correctChannelId = common.HexToHash(`252e8d12b641d8dd3cde74d299047963c99ce52bded2fbd38afa8e07b76a9306`)
var correctStateHash = common.HexToHash(`867a304a6c24962522085dc09c09b47413897a13700e94190c4e3320af0a3779`)
var correctChannelId = common.HexToHash(`6c39f3700c1d9a3dabcca3397083bf1460adbd36628c516eb9a05f7577cb5134`)
var correctStateHash = common.HexToHash(`a5b67e0f29a8d82f5f758f205d11224c02a043228bb9201ae633e75e18c5ff9a`)
var signerPrivateKey = common.Hex2Bytes(`caab404f975b4620747174a75f08d98b4e5a7053b691b41bcfc0d839d48b7634`)
var signerAddress = common.HexToAddress(`F5A1BB5607C9D079E46d1B3Dc33f257d937b43BD`)
var correctSignature = Signature{
R: common.Hex2Bytes(`704b3afcc6e702102ca1af3f73cf3b37f3007f368c40e8b81ca823a65740a053`),
S: common.Hex2Bytes(`14040ad4c598dbb055a50430142a13518e1330b79d24eed86fcbdff1a7a95589`),
R: common.Hex2Bytes(`be2d27ae0892e2981b31e017c8cb6f99bc0ccd1ae7d1b06fc69f1311f61c3e01`),
S: common.Hex2Bytes(`21420562c8227a3aa3b8e15574f93fa62b64f429ae727578dceea37f6083742e`),
V: byte(27),
}

Expand Down Expand Up @@ -63,7 +64,7 @@ func TestSign(t *testing.T) {
want_r, want_s, want_v := correctSignature.R, correctSignature.S, correctSignature.V
got, error := TestState.Sign(signerPrivateKey)
got_r, got_s, got_v := got.R, got.S, got.V

fmt.Printf("R: %s, S: %s, V: %v\n", common.Bytes2Hex(got_r), common.Bytes2Hex(got_s), got_v)
if error != nil {
t.Error(error)
}
Expand Down Expand Up @@ -99,7 +100,7 @@ func TestEqualParticipants(t *testing.T) {

func TestEqual(t *testing.T) {
want := State{
ChainId: chainId,
ChainId: TestState.ChainId,
Participants: []types.Address{
common.HexToAddress(`0xF5A1BB5607C9D079E46d1B3Dc33f257d937b43BD`), // private key caab404f975b4620747174a75f08d98b4e5a7053b691b41bcfc0d839d48b7634
common.HexToAddress(`0x760bf27cd45036a6C486802D30B5D90CfFBE31FE`), // private key 62ecd49c4ccb41a70ad46532aed63cf815de15864bc415c87d507afd6a5e8da2
Expand Down
4 changes: 1 addition & 3 deletions channel/state/test-fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"github.com/statechannels/go-nitro/types"
)

var chainId, _ = big.NewInt(0).SetString("9001", 10)

var TestOutcome = outcome.Exit{
outcome.SingleAssetExit{
Asset: types.Address{},
Expand All @@ -27,7 +25,7 @@ var TestOutcome = outcome.Exit{
}

var TestState = State{
ChainId: chainId,
ChainId: big.NewInt(1337),
Participants: []types.Address{
common.HexToAddress(`0xF5A1BB5607C9D079E46d1B3Dc33f257d937b43BD`), // private key caab404f975b4620747174a75f08d98b4e5a7053b691b41bcfc0d839d48b7634
common.HexToAddress(`0x760bf27cd45036a6C486802D30B5D90CfFBE31FE`), // private key 62ecd49c4ccb41a70ad46532aed63cf815de15864bc415c87d507afd6a5e8da2
Expand Down
15 changes: 10 additions & 5 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Client struct {
completedObjectives chan protocols.ObjectiveId
failedObjectives chan protocols.ObjectiveId
receivedVouchers chan payments.Voucher
chainId *big.Int
}

// New is the constructor for a Client. It accepts a messaging service, a chain service, and a store as injected dependencies.
Expand All @@ -37,7 +38,11 @@ func New(messageService messageservice.MessageService, chainservice chainservice
if metricsApi == nil {
metricsApi = &engine.NoOpMetrics{}
}

chainId, err := chainservice.GetChainId()
if err != nil {
panic(err)
}
c.chainId = chainId
c.engine = engine.New(messageService, chainservice, store, logDestination, policymaker, metricsApi)
c.completedObjectives = make(chan protocols.ObjectiveId, 100)
c.failedObjectives = make(chan protocols.ObjectiveId, 100)
Expand Down Expand Up @@ -109,7 +114,7 @@ func (c *Client) CreateVirtualPaymentChannel(Intermediaries []types.Address, Cou
// Send the event to the engine
c.engine.ObjectiveRequestsFromAPI <- objectiveRequest

return objectiveRequest.Response(*c.Address)
return objectiveRequest.Response(*c.Address, c.chainId)
}

// CloseVirtualChannel attempts to close and defund the given virtually funded channel.
Expand All @@ -122,7 +127,7 @@ func (c *Client) CloseVirtualChannel(channelId types.Destination) protocols.Obje
// Send the event to the engine
c.engine.ObjectiveRequestsFromAPI <- objectiveRequest

return objectiveRequest.Id(*c.Address)
return objectiveRequest.Id(*c.Address, c.chainId)

}

Expand All @@ -142,7 +147,7 @@ func (c *Client) CreateLedgerChannel(Counterparty types.Address, ChallengeDurati
// Send the event to the engine
c.engine.ObjectiveRequestsFromAPI <- objectiveRequest

return objectiveRequest.Response(*c.Address)
return objectiveRequest.Response(*c.Address, c.chainId)

}

Expand All @@ -156,7 +161,7 @@ func (c *Client) CloseLedgerChannel(channelId types.Destination) protocols.Objec
// Send the event to the engine
c.engine.ObjectiveRequestsFromAPI <- objectiveRequest

return objectiveRequest.Id(*c.Address)
return objectiveRequest.Id(*c.Address, c.chainId)

}

Expand Down
2 changes: 2 additions & 0 deletions client/engine/chainservice/chainservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,6 @@ type ChainService interface {
GetConsensusAppAddress() types.Address
// GetVirtualPaymentAppAddress returns the address of a deployed VirtualPaymentApp
GetVirtualPaymentAppAddress() types.Address
// GetChainId returns the id of the chain the service is connected to
GetChainId() (*big.Int, error)
}
5 changes: 5 additions & 0 deletions client/engine/chainservice/eth_chainservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var depositedTopic = crypto.Keccak256Hash([]byte("Deposited(bytes32,address,uint
type ethChain interface {
bind.ContractBackend
ethereum.TransactionReader
ChainID(ctx context.Context) (*big.Int, error)
}

type EthChainService struct {
Expand Down Expand Up @@ -336,3 +337,7 @@ func (ecs *EthChainService) GetConsensusAppAddress() types.Address {
func (ecs *EthChainService) GetVirtualPaymentAppAddress() types.Address {
return ecs.virtualPaymentAppAddress
}

func (ecs *EthChainService) GetChainId() (*big.Int, error) {
return ecs.chain.ChainID(context.Background())
}
6 changes: 6 additions & 0 deletions client/engine/chainservice/mock_chainservice.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package chainservice

import (
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/statechannels/go-nitro/protocols"
"github.com/statechannels/go-nitro/types"
Expand Down Expand Up @@ -50,3 +52,7 @@ func (mc *MockChainService) GetVirtualPaymentAppAddress() types.Address {
func (mc *MockChainService) EventFeed() <-chan Event {
return mc.eventFeed
}

func (mc *MockChainService) GetChainId() (*big.Int, error) {
return big.NewInt(TEST_CHAIN_ID), nil
}
25 changes: 20 additions & 5 deletions client/engine/chainservice/simulated_backend_chainservice.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package chainservice

import (
"context"
"errors"
"io"
"math/big"
Expand All @@ -18,6 +19,9 @@ import (
"github.com/statechannels/go-nitro/types"
)

// This is the chain id used by the simulated backend as well as hardhat
const TEST_CHAIN_ID = 1337

var ErrUnableToAssignBigInt = errors.New("simulated_backend_chainservice: unable to assign BigInt")

type binding[T any] struct {
Expand All @@ -32,20 +36,30 @@ type Bindings struct {
VirtualPaymentApp binding[VirtualPaymentApp.VirtualPaymentApp]
}

type simulatedChain interface {
type SimulatedChain interface {
ethChain
Commit() common.Hash
Close() error
}

// This is used to wrap the simulated backend so that we can provide a ChainID function like a real eth client
type BackendWrapper struct {
*backends.SimulatedBackend
}

func (b *BackendWrapper) ChainID(ctx context.Context) (*big.Int, error) {
return big.NewInt(TEST_CHAIN_ID), nil
}

// SimulatedBackendChainService extends EthChainService to automatically mine a block for every transaction
type SimulatedBackendChainService struct {
*EthChainService
sim simulatedChain
sim SimulatedChain
}

// NewSimulatedBackendChainService constructs a chain service that submits transactions to a NitroAdjudicator
// and listens to events from an eventSource
func NewSimulatedBackendChainService(sim simulatedChain, bindings Bindings,
func NewSimulatedBackendChainService(sim SimulatedChain, bindings Bindings,
txSigner *bind.TransactOpts, logDestination io.Writer) (ChainService, error) {
ethChainService, err := NewEthChainService(sim,
bindings.Adjudicator.Contract,
Expand All @@ -72,7 +86,7 @@ func (sbcs *SimulatedBackendChainService) SendTransaction(tx protocols.ChainTran
}

// SetupSimulatedBackend creates a new SimulatedBackend with the supplied number of transacting accounts, deploys the Nitro Adjudicator and returns both.
func SetupSimulatedBackend(numAccounts uint64) (*backends.SimulatedBackend, Bindings, []*bind.TransactOpts, error) {
func SetupSimulatedBackend(numAccounts uint64) (SimulatedChain, Bindings, []*bind.TransactOpts, error) {
accounts := make([]*bind.TransactOpts, numAccounts)
genesisAlloc := make(map[common.Address]core.GenesisAccount)
contractBindings := Bindings{}
Expand Down Expand Up @@ -138,7 +152,8 @@ func SetupSimulatedBackend(numAccounts uint64) (*backends.SimulatedBackend, Bind
VirtualPaymentApp: binding[VirtualPaymentApp.VirtualPaymentApp]{virtualPaymentAppAddress, vpa},
}
sim.Commit()
return sim, contractBindings, accounts, nil

return &BackendWrapper{sim}, contractBindings, accounts, nil
}

func (sbcs *SimulatedBackendChainService) GetConsensusAppAddress() types.Address {
Expand Down
14 changes: 11 additions & 3 deletions client/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,21 @@ func (e *Engine) handleChainEvent(chainEvent chainservice.Event) (EngineEvent, e
func (e *Engine) handleObjectiveRequest(or protocols.ObjectiveRequest) (EngineEvent, error) {
defer e.metrics.RecordFunctionDuration()()
myAddress := *e.store.GetAddress()
objectiveId := or.Id(myAddress)

chainId, err := e.chain.GetChainId()

if err != nil {
return EngineEvent{}, fmt.Errorf("could get chain id from chain service: %w", err)
}

objectiveId := or.Id(myAddress, chainId)
e.logger.Printf("handling new objective request for %s", objectiveId)
e.metrics.RecordObjectiveStarted(objectiveId)

switch request := or.(type) {

case virtualfund.ObjectiveRequest:
vfo, err := virtualfund.NewObjective(request, true, myAddress, e.store.GetConsensusChannel)
vfo, err := virtualfund.NewObjective(request, true, myAddress, chainId, e.store.GetConsensusChannel)
if err != nil {
return EngineEvent{}, fmt.Errorf("handleAPIEvent: Could not create objective for %+v: %w", request, err)
}
Expand Down Expand Up @@ -392,7 +400,7 @@ func (e *Engine) handleObjectiveRequest(or protocols.ObjectiveRequest) (EngineEv
return e.attemptProgress(&vdfo)

case directfund.ObjectiveRequest:
dfo, err := directfund.NewObjective(request, true, myAddress, e.store.GetChannelsByParticipant, e.store.GetConsensusChannel)
dfo, err := directfund.NewObjective(request, true, myAddress, chainId, e.store.GetChannelsByParticipant, e.store.GetConsensusChannel)
if err != nil {
return EngineEvent{}, fmt.Errorf("handleAPIEvent: Could not create objective for %+v: %w", request, err)
}
Expand Down
Loading

0 comments on commit eafac67

Please sign in to comment.