Browse Source

Merge pull request #500 from hermeznetwork/fix/exitnonces1

Fix exit tree nonces
feature/sql-semaphore1
arnau 3 years ago
committed by GitHub
parent
commit
733ffb6399
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 1 deletions
  1. +0
    -1
      txprocessor/txprocessor.go
  2. +52
    -0
      txprocessor/txprocessor_test.go

+ 0
- 1
txprocessor/txprocessor.go

@ -1134,7 +1134,6 @@ func (tp *TxProcessor) applyExit(coordIdxsMap map[common.TokenID]common.Idx,
} else if err != nil { } else if err != nil {
return exitAccount, false, tracerr.Wrap(err) return exitAccount, false, tracerr.Wrap(err)
} }
exitAccount.Nonce = exitAccount.Nonce + 1
// 1b. if idx already exist in exitTree: // 1b. if idx already exist in exitTree:
if tp.zki != nil { if tp.zki != nil {

+ 52
- 0
txprocessor/txprocessor_test.go

@ -791,6 +791,9 @@ func TestMultipleCoordIdxForTokenID(t *testing.T) {
} }
func TestTwoExits(t *testing.T) { func TestTwoExits(t *testing.T) {
// In the first part we generate a batch with two force exits for the
// same account of 20 each. The txprocessor output should be a single
// exitInfo with balance of 40.
dir, err := ioutil.TempDir("", "tmpdb") dir, err := ioutil.TempDir("", "tmpdb")
require.NoError(t, err) require.NoError(t, err)
defer assert.NoError(t, os.RemoveAll(dir)) defer assert.NoError(t, os.RemoveAll(dir))
@ -852,4 +855,53 @@ func TestTwoExits(t *testing.T) {
acc, err := sdb.GetAccount(256) acc, err := sdb.GetAccount(256)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, big.NewInt(60), acc.Balance) assert.Equal(t, big.NewInt(60), acc.Balance)
// In the second part we start a fresh statedb and generate a batch
// with one force exit for the same account as before. The txprocessor
// output should be a single exitInfo with balance of 40, and the exit
// merkle tree proof should be equal to the previous one.
dir2, err := ioutil.TempDir("", "tmpdb")
require.NoError(t, err)
defer assert.NoError(t, os.RemoveAll(dir2))
sdb2, err := statedb.NewStateDB(dir2, 128, statedb.TypeSynchronizer, 32)
assert.NoError(t, err)
tc = til.NewContext(chainID, common.RollupConstMaxL1UserTx)
// Single exit with balance of both exits in previous set. The exit
// root should match.
set2 := `
Type: Blockchain
CreateAccountDeposit(0) A: 100
> batchL1 // freeze L1User{1}
> batchL1 // forge L1User{1}
ForceExit(0) A: 40
> batchL1 // freeze L1User{2}
> batchL1 // forge L1User{2}
> block
`
blocks, err = tc.GenerateBlocks(set2)
require.NoError(t, err)
err = tc.FillBlocksExtra(blocks, &til.ConfigExtra{})
require.NoError(t, err)
err = tc.FillBlocksForgedL1UserTxs(blocks)
require.NoError(t, err)
tp = NewTxProcessor(sdb2, config)
ptOuts2 := []*ProcessTxOutput{}
for _, block := range blocks {
for _, batch := range block.Rollup.Batches {
ptOut, err := tp.ProcessTxs(nil, batch.L1UserTxs, nil, nil)
require.NoError(t, err)
ptOuts2 = append(ptOuts2, ptOut)
}
}
assert.Equal(t, ptOuts[3].ExitInfos[0].MerkleProof, ptOuts2[3].ExitInfos[0].MerkleProof)
} }

Loading…
Cancel
Save