Skip to content

Commit

Permalink
feat: PaymentInFlightExitRouter.inFlightExits() accepts an array of e…
Browse files Browse the repository at this point in the history
…xitIds (#583)

* feat: update IFE getter to work with multiple IFEs instead of one at a time

* fix: exits() and inFlightExits() should take multiple exit IDs

* fix: wrong function args in python tests

* fix: incorrect exits access in IFE tests
  • Loading branch information
unnawut authored Feb 14, 2020
1 parent b3c4fd2 commit d478475
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,15 @@ contract PaymentInFlightExitRouter is

/**
* @notice Getter functions to retrieve in-flight exit data of the PaymentExitGame
* @param exitId The exit ID of the in-flight exit
* @param exitIds The exit IDs of the in-flight exits
*/
function inFlightExits(uint160 exitId) public view returns (PaymentExitDataModel.InFlightExit memory) {
return inFlightExitMap.exits[exitId];
function inFlightExits(uint160[] calldata exitIds) external view returns (PaymentExitDataModel.InFlightExit[] memory) {
PaymentExitDataModel.InFlightExit[] memory exits = new PaymentExitDataModel.InFlightExit[](exitIds.length);
for (uint i = 0; i < exitIds.length; i++) {
uint160 exitId = exitIds[i];
exits[i] = inFlightExitMap.exits[exitId];
}
return exits;
}

/**
Expand Down
60 changes: 30 additions & 30 deletions plasma_framework/docs/contracts/PaymentInFlightExitRouter.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ event InFlightExitDeleted(uint160 indexed exitId);
## Functions

- [(struct PaymentExitGameArgs.Args args)](#)
- [inFlightExits(uint160 exitId)](#inflightexits)
- [inFlightExits(uint160[] exitIds)](#inflightexits)
- [startInFlightExit(struct PaymentInFlightExitRouterArgs.StartExitArgs args)](#startinflightexit)
- [piggybackInFlightExitOnInput(struct PaymentInFlightExitRouterArgs.PiggybackInFlightExitOnInputArgs args)](#piggybackinflightexitoninput)
- [piggybackInFlightExitOnOutput(struct PaymentInFlightExitRouterArgs.PiggybackInFlightExitOnOutputArgs args)](#piggybackinflightexitonoutput)
Expand All @@ -71,7 +71,7 @@ event InFlightExitDeleted(uint160 indexed exitId);
- [piggybackBondSize()](#piggybackbondsize)
- [updatePiggybackBondSize(uint128 newBondSize)](#updatepiggybackbondsize)

###
###

```js
function (struct PaymentExitGameArgs.Args args) public nonpayable
Expand All @@ -81,136 +81,136 @@ function (struct PaymentExitGameArgs.Args args) public nonpayable

| Name | Type | Description |
| ------------- |------------- | -----|
| args | struct PaymentExitGameArgs.Args | |
| args | struct PaymentExitGameArgs.Args | |

### inFlightExits

Getter functions to retrieve in-flight exit data of the PaymentExitGame

```js
function inFlightExits(uint160 exitId) public view
returns(struct PaymentExitDataModel.InFlightExit)
function inFlightExits(uint160[] exitIds) external view
returns(struct PaymentExitDataModel.InFlightExit[])
```

**Arguments**

| Name | Type | Description |
| ------------- |------------- | -----|
| exitId | uint160 | The exit ID of the in-flight exit |
| exitIds | uint160[] | The exit IDs of the in-flight exits |

### startInFlightExit

Starts withdrawal from a transaction that may be in-flight

```js
function startInFlightExit(struct PaymentInFlightExitRouterArgs.StartExitArgs args) public payable nonReentrant onlyWithValue
function startInFlightExit(struct PaymentInFlightExitRouterArgs.StartExitArgs args) public payable nonReentrant onlyWithValue
```

**Arguments**

| Name | Type | Description |
| ------------- |------------- | -----|
| args | struct PaymentInFlightExitRouterArgs.StartExitArgs | Input argument data to challenge (see also struct 'StartExitArgs') |
| args | struct PaymentInFlightExitRouterArgs.StartExitArgs | Input argument data to challenge (see also struct 'StartExitArgs') |

### piggybackInFlightExitOnInput

Piggyback on an input of an in-flight exiting tx. Processed only if the in-flight exit is non-canonical.

```js
function piggybackInFlightExitOnInput(struct PaymentInFlightExitRouterArgs.PiggybackInFlightExitOnInputArgs args) public payable nonReentrant onlyWithValue
function piggybackInFlightExitOnInput(struct PaymentInFlightExitRouterArgs.PiggybackInFlightExitOnInputArgs args) public payable nonReentrant onlyWithValue
```

**Arguments**

| Name | Type | Description |
| ------------- |------------- | -----|
| args | struct PaymentInFlightExitRouterArgs.PiggybackInFlightExitOnInputArgs | Input argument data to piggyback (see also struct 'PiggybackInFlightExitOnInputArgs') |
| args | struct PaymentInFlightExitRouterArgs.PiggybackInFlightExitOnInputArgs | Input argument data to piggyback (see also struct 'PiggybackInFlightExitOnInputArgs') |

### piggybackInFlightExitOnOutput

Piggyback on an output of an in-flight exiting tx. Processed only if the in-flight exit is canonical.

```js
function piggybackInFlightExitOnOutput(struct PaymentInFlightExitRouterArgs.PiggybackInFlightExitOnOutputArgs args) public payable nonReentrant onlyWithValue
function piggybackInFlightExitOnOutput(struct PaymentInFlightExitRouterArgs.PiggybackInFlightExitOnOutputArgs args) public payable nonReentrant onlyWithValue
```

**Arguments**

| Name | Type | Description |
| ------------- |------------- | -----|
| args | struct PaymentInFlightExitRouterArgs.PiggybackInFlightExitOnOutputArgs | Input argument data to piggyback (see also struct 'PiggybackInFlightExitOnOutputArgs') |
| args | struct PaymentInFlightExitRouterArgs.PiggybackInFlightExitOnOutputArgs | Input argument data to piggyback (see also struct 'PiggybackInFlightExitOnOutputArgs') |

### challengeInFlightExitNotCanonical

Challenges an in-flight exit to be non-canonical

```js
function challengeInFlightExitNotCanonical(struct PaymentInFlightExitRouterArgs.ChallengeCanonicityArgs args) public nonpayable nonReentrant
function challengeInFlightExitNotCanonical(struct PaymentInFlightExitRouterArgs.ChallengeCanonicityArgs args) public nonpayable nonReentrant
```

**Arguments**

| Name | Type | Description |
| ------------- |------------- | -----|
| args | struct PaymentInFlightExitRouterArgs.ChallengeCanonicityArgs | Input argument data to challenge (see also struct 'ChallengeCanonicityArgs') |
| args | struct PaymentInFlightExitRouterArgs.ChallengeCanonicityArgs | Input argument data to challenge (see also struct 'ChallengeCanonicityArgs') |

### respondToNonCanonicalChallenge

Respond to a non-canonical challenge by providing its position and by proving its correctness

```js
function respondToNonCanonicalChallenge(bytes inFlightTx, uint256 inFlightTxPos, bytes inFlightTxInclusionProof) public nonpayable nonReentrant
function respondToNonCanonicalChallenge(bytes inFlightTx, uint256 inFlightTxPos, bytes inFlightTxInclusionProof) public nonpayable nonReentrant
```

**Arguments**

| Name | Type | Description |
| ------------- |------------- | -----|
| inFlightTx | bytes | The RLP-encoded in-flight transaction |
| inFlightTxPos | uint256 | The position of the in-flight exiting transaction. The output index within the position is unused and should be set to 0 |
| inFlightTxInclusionProof | bytes | Proof that the in-flight exiting transaction is included in a Plasma block |
| inFlightTx | bytes | The RLP-encoded in-flight transaction |
| inFlightTxPos | uint256 | The position of the in-flight exiting transaction. The output index within the position is unused and should be set to 0 |
| inFlightTxInclusionProof | bytes | Proof that the in-flight exiting transaction is included in a Plasma block |

### challengeInFlightExitInputSpent

Challenges an exit from in-flight transaction input

```js
function challengeInFlightExitInputSpent(struct PaymentInFlightExitRouterArgs.ChallengeInputSpentArgs args) public nonpayable nonReentrant
function challengeInFlightExitInputSpent(struct PaymentInFlightExitRouterArgs.ChallengeInputSpentArgs args) public nonpayable nonReentrant
```

**Arguments**

| Name | Type | Description |
| ------------- |------------- | -----|
| args | struct PaymentInFlightExitRouterArgs.ChallengeInputSpentArgs | Argument data to challenge (see also struct 'ChallengeInputSpentArgs') |
| args | struct PaymentInFlightExitRouterArgs.ChallengeInputSpentArgs | Argument data to challenge (see also struct 'ChallengeInputSpentArgs') |

### challengeInFlightExitOutputSpent

Challenges an exit from in-flight transaction output

```js
function challengeInFlightExitOutputSpent(struct PaymentInFlightExitRouterArgs.ChallengeOutputSpent args) public nonpayable nonReentrant
function challengeInFlightExitOutputSpent(struct PaymentInFlightExitRouterArgs.ChallengeOutputSpent args) public nonpayable nonReentrant
```

**Arguments**

| Name | Type | Description |
| ------------- |------------- | -----|
| args | struct PaymentInFlightExitRouterArgs.ChallengeOutputSpent | Argument data to challenge (see also struct 'ChallengeOutputSpent') |
| args | struct PaymentInFlightExitRouterArgs.ChallengeOutputSpent | Argument data to challenge (see also struct 'ChallengeOutputSpent') |

### deleteNonPiggybackedInFlightExit

Deletes in-flight exit if the first phase has passed and not being piggybacked

```js
function deleteNonPiggybackedInFlightExit(uint160 exitId) public nonpayable nonReentrant
function deleteNonPiggybackedInFlightExit(uint160 exitId) public nonpayable nonReentrant
```

**Arguments**

| Name | Type | Description |
| ------------- |------------- | -----|
| exitId | uint160 | The exitId of the in-flight exit |
| exitId | uint160 | The exitId of the in-flight exit |

### processInFlightExit

Expand All @@ -224,8 +224,8 @@ function processInFlightExit(uint160 exitId, address token) internal nonpayable

| Name | Type | Description |
| ------------- |------------- | -----|
| exitId | uint160 | The in-flight exit ID |
| token | address | The token (in erc20 address or address(0) for ETH) of the exiting output |
| exitId | uint160 | The in-flight exit ID |
| token | address | The token (in erc20 address or address(0) for ETH) of the exiting output |

### startIFEBondSize

Expand All @@ -246,14 +246,14 @@ returns(uint128)
Updates the in-flight exit bond size, taking two days to become effective.

```js
function updateStartIFEBondSize(uint128 newBondSize) public nonpayable onlyFrom
function updateStartIFEBondSize(uint128 newBondSize) public nonpayable onlyFrom
```

**Arguments**

| Name | Type | Description |
| ------------- |------------- | -----|
| newBondSize | uint128 | The new bond size |
| newBondSize | uint128 | The new bond size |

### piggybackBondSize

Expand All @@ -274,14 +274,14 @@ returns(uint128)
Updates the piggyback bond size, taking two days to become effective

```js
function updatePiggybackBondSize(uint128 newBondSize) public nonpayable onlyFrom
function updatePiggybackBondSize(uint128 newBondSize) public nonpayable onlyFrom
```

**Arguments**

| Name | Type | Description |
| ------------- |------------- | -----|
| newBondSize | uint128 | The new bond size |
| newBondSize | uint128 | The new bond size |

## Contracts

Expand Down
6 changes: 3 additions & 3 deletions plasma_framework/python_tests/testlang/testlang.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def get_standard_exit(self, utxo_pos):
"""

exit_id = self.get_standard_exit_id(utxo_pos)
exit_info = self.root_chain.exits(exit_id)
exit_info = self.root_chain.exits([exit_id])
return StandardExit(*exit_info[0])

def get_standard_exit_id(self, utxo_pos):
Expand Down Expand Up @@ -485,8 +485,8 @@ def challenge_in_flight_exit_output_spent(self, in_flight_tx_id, spending_tx_id,
def get_in_flight_exit(self, in_flight_tx_id):
in_flight_tx = self.child_chain.get_transaction(in_flight_tx_id)
exit_id = self.root_chain.getInFlightExitId(in_flight_tx.encoded)
exit_info = self.root_chain.inFlightExits(exit_id)
return InFlightExit(self.root_chain, in_flight_tx, *exit_info)
exit_info = self.root_chain.inFlightExits([exit_id])
return InFlightExit(self.root_chain, in_flight_tx, *exit_info[0])

def delete_in_flight_exit(self, in_flight_tx_id):
in_flight_tx = self.child_chain.get_transaction(in_flight_tx_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_start_standard_exit_old_utxo_has_required_exit_period_to_start_exit(tes
testlang.start_standard_exit(utxo.spend_id, utxo.owner)

_, _, next_exit_id = testlang.root_chain.getNextExit(testlang.root_chain.eth_vault_id, NULL_ADDRESS)
exits = testlang.root_chain.exits(next_exit_id)
exits = testlang.root_chain.exits([next_exit_id])
next_exit = StandardExit(*exits[0])
assert next_exit.position == utxo.spend_id

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,11 @@ def inFlightExitBond(self):
def piggybackBond(self):
return self.payment_exit_game.piggybackBondSize()

def exits(self, exit_id):
return self.payment_exit_game.standardExits([exit_id])
def exits(self, exit_ids):
return self.payment_exit_game.standardExits(exit_ids)

def inFlightExits(self, exit_id):
return self.payment_exit_game.inFlightExits(exit_id)
def inFlightExits(self, exit_ids):
return self.payment_exit_game.inFlightExits(exit_ids)

# additional convenience proxies (not taken from RootChain) #

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ contract('PaymentChallengeIFEInputSpent', ([_, alice, inputOwner, outputOwner, c
});

it('should remove the input from piggybacked', async () => {
const exit = await this.exitGame.inFlightExits(this.testData.exitId);
expect(new BN(exit.exitMap)).to.be.bignumber.equal(new BN(0));
const exits = await this.exitGame.inFlightExits([this.testData.exitId]);
expect(new BN(exits[0].exitMap)).to.be.bignumber.equal(new BN(0));
});

it('should pay the piggyback bond to the challenger', async () => {
Expand All @@ -290,16 +290,16 @@ contract('PaymentChallengeIFEInputSpent', ([_, alice, inputOwner, outputOwner, c

it('should remove the input from piggybacked', async () => {
// Before the challenge, both inputs should be in the exitMap
let exit = await this.exitGame.inFlightExits(this.testData.exitId);
expect(new BN(exit.exitMap)).to.be.bignumber.equal(new BN(0b11));
let exits = await this.exitGame.inFlightExits([this.testData.exitId]);
expect(new BN(exits[0].exitMap)).to.be.bignumber.equal(new BN(0b11));

await this.exitGame.challengeInFlightExitInputSpent(
this.challengeArgs, { from: challenger },
);

// After the challenge, only input 1 should be in the exitMap
exit = await this.exitGame.inFlightExits(this.testData.exitId);
expect(new BN(exit.exitMap)).to.be.bignumber.equal(new BN(0b01));
exits = await this.exitGame.inFlightExits([this.testData.exitId]);
expect(new BN(exits[0].exitMap)).to.be.bignumber.equal(new BN(0b01));
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,22 +324,22 @@ contract('PaymentChallengeIFENotCanonical', ([_, ifeOwner, inputOwner, outputOwn
it('should set the oldest competitorPosition', async () => {
const expectedCompetitorPosition = new BN(this.challengeArgs.competingTxPos);

const exit = await this.exitGame.inFlightExits(this.exitId);
const exits = await this.exitGame.inFlightExits([this.exitId]);

const oldestCompetitorPosition = new BN(exit.oldestCompetitorPosition);
const oldestCompetitorPosition = new BN(exits[0].oldestCompetitorPosition);
expect(oldestCompetitorPosition).to.be.bignumber.equal(expectedCompetitorPosition);
});

it('should set the bond owner to challenger', async () => {
const exit = await this.exitGame.inFlightExits(this.exitId);
const exits = await this.exitGame.inFlightExits([this.exitId]);

expect(exit.bondOwner).to.be.equal(challenger);
expect(exits[0].bondOwner).to.be.equal(challenger);
});

it('should flag the exit non-canonical', async () => {
const exit = await this.exitGame.inFlightExits(this.exitId);
const exits = await this.exitGame.inFlightExits([this.exitId]);

expect(exit.isCanonical).to.be.false;
expect(exits[0].isCanonical).to.be.false;
});
});

Expand Down Expand Up @@ -597,9 +597,9 @@ contract('PaymentChallengeIFENotCanonical', ([_, ifeOwner, inputOwner, outputOwn
{ from: ifeOwner },
);

const exit = await this.exitGame.inFlightExits(this.exitId);
const exits = await this.exitGame.inFlightExits([this.exitId]);

expect(exit.isCanonical).to.be.true;
expect(exits[0].isCanonical).to.be.true;
});

it('should set bond owner to caller', async () => {
Expand All @@ -610,9 +610,9 @@ contract('PaymentChallengeIFENotCanonical', ([_, ifeOwner, inputOwner, outputOwn
{ from: ifeOwner },
);

const exit = await this.exitGame.inFlightExits(this.exitId);
const exits = await this.exitGame.inFlightExits([this.exitId]);

expect(exit.bondOwner).to.equal(ifeOwner);
expect(exits[0].bondOwner).to.equal(ifeOwner);
});

it('should set oldest competitor position to response position', async () => {
Expand All @@ -623,9 +623,9 @@ contract('PaymentChallengeIFENotCanonical', ([_, ifeOwner, inputOwner, outputOwn
{ from: ifeOwner },
);

const exit = await this.exitGame.inFlightExits(this.exitId);
const exits = await this.exitGame.inFlightExits([this.exitId]);

const oldestCompetitorPosition = new BN(exit.oldestCompetitorPosition);
const oldestCompetitorPosition = new BN(exits[0].oldestCompetitorPosition);
expect(oldestCompetitorPosition).to.be.bignumber.equal(new BN(this.inFlightTxPos));
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ contract('PaymentDeleteInFlightExit', ([_, bondOwner, inputOwner, outputOwner])
});

it('should delete the in-flight exit data', async () => {
const exit = await this.exitGame.inFlightExits(exitId);
expect(exit.exitStartTimestamp).to.equal('0');
const exits = await this.exitGame.inFlightExits([exitId]);
expect(exits[0].exitStartTimestamp).to.equal('0');
});

it('should emit InFlightExitDeleted event', async () => {
Expand Down
Loading

0 comments on commit d478475

Please sign in to comment.