Commit bacb3c41 authored by mergify[bot]'s avatar mergify[bot] Committed by GitHub

Merge branch 'develop' into fix/bindings-deterministic

parents 918ae29e 61cb88ac
3b1129b5bc43ba22a9bcf4e4323c5a9df0023140
...@@ -45,7 +45,7 @@ This tutorial was checked on: ...@@ -45,7 +45,7 @@ This tutorial was checked on:
| Go | 1.20 | `sudo apt update` <br> `wget https://go.dev/dl/go1.20.linux-amd64.tar.gz` <br> `tar xvzf go1.20.linux-amd64.tar.gz` <br> `sudo cp go/bin/go /usr/bin/go` <br> `sudo mv go /usr/lib` <br> `echo export GOROOT=/usr/lib/go >> ~/.bashrc` | Go | 1.20 | `sudo apt update` <br> `wget https://go.dev/dl/go1.20.linux-amd64.tar.gz` <br> `tar xvzf go1.20.linux-amd64.tar.gz` <br> `sudo cp go/bin/go /usr/bin/go` <br> `sudo mv go /usr/lib` <br> `echo export GOROOT=/usr/lib/go >> ~/.bashrc`
| Node | 16.19.0 | `curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -` <br> `sudo apt-get install -y nodejs npm` | Node | 16.19.0 | `curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -` <br> `sudo apt-get install -y nodejs npm`
| yarn | 1.22.19 | `sudo npm install -g yarn` | yarn | 1.22.19 | `sudo npm install -g yarn`
| Foundry | 0.2.0 | `curl -L https://foundry.paradigm.xyz | bash` <br> `. ~/.bashrc` <br> `foundryup` | Foundry | 0.2.0 | `yarn install:foundry`
## Build the Source Code ## Build the Source Code
......
...@@ -49,9 +49,8 @@ func (a *Agent) move(claim, parent Claim) error { ...@@ -49,9 +49,8 @@ func (a *Agent) move(claim, parent Claim) error {
if err != nil || move == nil { if err != nil || move == nil {
return err return err
} }
// TODO(CLI-4123): Don't send duplicate responses if a.game.IsDuplicate(*move) {
// if a.game.IsDuplicate(move) { return nil
// return nil }
// }
return a.responder.Respond(context.TODO(), *move) return a.responder.Respond(context.TODO(), *move)
} }
...@@ -22,6 +22,8 @@ type Game interface { ...@@ -22,6 +22,8 @@ type Game interface {
claim Claim claim Claim
parent Claim parent Claim
} }
IsDuplicate(claim Claim) bool
} }
// Node is a node in the game state tree. // Node is a node in the game state tree.
...@@ -33,17 +35,21 @@ type Node struct { ...@@ -33,17 +35,21 @@ type Node struct {
// gameState is a struct that represents the state of a dispute game. // gameState is a struct that represents the state of a dispute game.
// The game state implements the [Game] interface. // The game state implements the [Game] interface.
type gameState struct { type gameState struct {
root Node root Node
claims map[ClaimData]Claim
} }
// NewGameState returns a new game state. // NewGameState returns a new game state.
// The provided [Claim] is used as the root node. // The provided [Claim] is used as the root node.
func NewGameState(root Claim) *gameState { func NewGameState(root Claim) *gameState {
claims := make(map[ClaimData]Claim)
claims[root.ClaimData] = root
return &gameState{ return &gameState{
root: Node{ root: Node{
self: root, self: root,
children: make([]*Node, 0), children: make([]*Node, 0),
}, },
claims: claims,
} }
} }
...@@ -116,10 +122,16 @@ func (g *gameState) Put(claim Claim) error { ...@@ -116,10 +122,16 @@ func (g *gameState) Put(claim Claim) error {
// Add the node to the tree. // Add the node to the tree.
found.children = append(found.children, &node) found.children = append(found.children, &node)
g.claims[claim.ClaimData] = claim
return nil return nil
} }
func (g *gameState) IsDuplicate(claim Claim) bool {
_, ok := g.claims[claim.ClaimData]
return ok
}
// recurseTreePairs recursively walks down the tree from the root node // recurseTreePairs recursively walks down the tree from the root node
// returning a list of claim and parent pairs. // returning a list of claim and parent pairs.
func (g *gameState) recurseTreePairs(current *Node) []struct { func (g *gameState) recurseTreePairs(current *Node) []struct {
......
...@@ -35,6 +35,21 @@ func createTestClaims() (Claim, Claim, Claim) { ...@@ -35,6 +35,21 @@ func createTestClaims() (Claim, Claim, Claim) {
return top, middle, bottom return top, middle, bottom
} }
func TestIsDuplicate(t *testing.T) {
// Setup the game state.
top, middle, bottom := createTestClaims()
g := NewGameState(top)
err := g.Put(middle)
require.NoError(t, err)
// Top + Middle should be duplicates
require.True(t, g.IsDuplicate(top))
require.True(t, g.IsDuplicate(middle))
// Bottom should not be a duplicate
require.False(t, g.IsDuplicate(bottom))
}
// TestGame_Put_RootAlreadyExists tests the [Game.Put] method using a [gameState] // TestGame_Put_RootAlreadyExists tests the [Game.Put] method using a [gameState]
// instance errors when the root claim already exists in state. // instance errors when the root claim already exists in state.
func TestGame_Put_RootAlreadyExists(t *testing.T) { func TestGame_Put_RootAlreadyExists(t *testing.T) {
......
...@@ -11,12 +11,14 @@ RUN apt-get update && \ ...@@ -11,12 +11,14 @@ RUN apt-get update && \
chmod +x ./rustup.sh && \ chmod +x ./rustup.sh && \
./rustup.sh -y ./rustup.sh -y
# move the foundryrc file to the foundry dir
WORKDIR /opt/foundry WORKDIR /opt/foundry
COPY ../../.foundryrc ./.foundryrc
# Only diff from upstream docker image is this clone instead # Only diff from upstream docker image is this clone instead
# of COPY. We select a specific commit to use. # of COPY. We select a specific commit to use.
RUN git clone https://github.com/foundry-rs/foundry.git . \ RUN git clone https://github.com/foundry-rs/foundry.git . \
&& git checkout 3b1129b5bc43ba22a9bcf4e4323c5a9df0023140 && git checkout $(cat .foundryrc)
RUN source $HOME/.profile && \ RUN source $HOME/.profile && \
cargo build --release && \ cargo build --release && \
......
...@@ -39,7 +39,9 @@ ...@@ -39,7 +39,9 @@
"ready": "yarn lint && yarn test", "ready": "yarn lint && yarn test",
"prepare": "husky install", "prepare": "husky install",
"release": "yarn build && yarn changeset publish", "release": "yarn build && yarn changeset publish",
"update:yarn": "yarn set version 1.x" "update:yarn": "yarn set version 1.x",
"install:foundry": "curl -L https://foundry.paradigm.xyz | bash && yarn update:foundry",
"update:foundry": "foundryup -C $(cat .foundryrc)"
}, },
"devDependencies": { "devDependencies": {
"@babel/eslint-parser": "^7.18.2", "@babel/eslint-parser": "^7.18.2",
......
...@@ -56,16 +56,17 @@ npm install @eth-optimism/contracts-bedrock ...@@ -56,16 +56,17 @@ npm install @eth-optimism/contracts-bedrock
We work on this repository with a combination of [Hardhat](https://hardhat.org) and [Foundry](https://getfoundry.sh/). We work on this repository with a combination of [Hardhat](https://hardhat.org) and [Foundry](https://getfoundry.sh/).
1. Install Foundry by following [the instructions located here](https://getfoundry.sh/). 1. Install node modules with yarn (v1) and Node.js (16+):
A specific version must be used.
```shell ```shell
foundryup -C 3b1129b5bc43ba22a9bcf4e4323c5a9df0023140 yarn install
``` ```
2. Install node modules with yarn (v1) and Node.js (16+):
1. Install the correct version of foundry (defined in the .foundryrc file in the root of this repo.
```shell
yarn install ```shell
``` yarn install:foundry
```
### Build ### Build
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment