mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Fix exit table, set delayed_withdrawn in exits
- In exit table, `instant_withdrawn`, `delayed_withdraw_request`, and
`delayed_withdrawn` were referencing batch_num. But these actions happen
outside a batch, so they should reference a block_num.
- Process delayed withdrawns:
- In Synchronizer, first match a Rollup delayed withdrawn request, with the
WDelayer deposit (via TxHash), and store the owner and token associated
with the delayed withdrawn.
- In HistoryDB: store the owner and token of a delayed withdrawal request
in the exit_tree, and set delayed_withdrawn when the withdraw is done in
the WDelayer.
- Update dependency of sqlx to master
- Last release of sqlx is from 2018 October, and it doesn't support
`NamedQuery` with a slice of structs, which is used in this commit.
This commit is contained in:
@@ -45,6 +45,16 @@ func (w *WDelayerBlock) addTransaction(tx *types.Transaction) *types.Transaction
|
||||
return tx
|
||||
}
|
||||
|
||||
func (w *WDelayerBlock) deposit(txHash ethCommon.Hash, owner, token ethCommon.Address, amount *big.Int) {
|
||||
w.Events.Deposit = append(w.Events.Deposit, eth.WDelayerEventDeposit{
|
||||
Owner: owner,
|
||||
Token: token,
|
||||
Amount: amount,
|
||||
DepositTimestamp: uint64(w.Eth.Time),
|
||||
TxHash: txHash,
|
||||
})
|
||||
}
|
||||
|
||||
// RollupBlock stores all the data related to the Rollup SC from an ethereum block
|
||||
type RollupBlock struct {
|
||||
State eth.RollupState
|
||||
@@ -57,6 +67,7 @@ type RollupBlock struct {
|
||||
|
||||
func (r *RollupBlock) addTransaction(tx *types.Transaction) *types.Transaction {
|
||||
txHash := tx.Hash()
|
||||
fmt.Printf("DBG txHash %v\n", txHash.Hex())
|
||||
r.Txs[txHash] = tx
|
||||
return tx
|
||||
}
|
||||
@@ -769,29 +780,36 @@ func (c *Client) RollupWithdrawMerkleProof(babyPubKey *babyjub.PublicKey, tokenI
|
||||
}
|
||||
r.State.ExitNullifierMap[numExitRoot][idx] = true
|
||||
|
||||
type data struct {
|
||||
BabyPubKey *babyjub.PublicKey
|
||||
TokenID uint32
|
||||
NumExitRoot int64
|
||||
Idx int64
|
||||
Amount *big.Int
|
||||
Siblings []*big.Int
|
||||
InstantWithdraw bool
|
||||
}
|
||||
tx = r.addTransaction(newTransaction("withdrawMerkleProof", data{
|
||||
BabyPubKey: babyPubKey,
|
||||
TokenID: tokenID,
|
||||
NumExitRoot: numExitRoot,
|
||||
Idx: idx,
|
||||
Amount: amount,
|
||||
Siblings: siblings,
|
||||
InstantWithdraw: instantWithdraw,
|
||||
}))
|
||||
r.Events.Withdraw = append(r.Events.Withdraw, eth.RollupEventWithdraw{
|
||||
Idx: uint64(idx),
|
||||
NumExitRoot: uint64(numExitRoot),
|
||||
InstantWithdraw: instantWithdraw,
|
||||
TxHash: tx.Hash(),
|
||||
})
|
||||
type data struct {
|
||||
babyPubKey *babyjub.PublicKey
|
||||
tokenID uint32
|
||||
numExitRoot int64
|
||||
idx int64
|
||||
amount *big.Int
|
||||
siblings []*big.Int
|
||||
instantWithdraw bool
|
||||
|
||||
if !instantWithdraw {
|
||||
w := nextBlock.WDelayer
|
||||
w.deposit(tx.Hash(), *c.addr, r.State.TokenList[int(tokenID)], amount)
|
||||
}
|
||||
return r.addTransaction(newTransaction("withdrawMerkleProof", data{
|
||||
babyPubKey: babyPubKey,
|
||||
tokenID: tokenID,
|
||||
numExitRoot: numExitRoot,
|
||||
idx: idx,
|
||||
amount: amount,
|
||||
siblings: siblings,
|
||||
instantWithdraw: instantWithdraw,
|
||||
})), nil
|
||||
return tx, nil
|
||||
}
|
||||
|
||||
type transactionData struct {
|
||||
@@ -804,6 +822,7 @@ func newTransaction(name string, value interface{}) *types.Transaction {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("DBG dataJSON: %v\n", string(data))
|
||||
return types.NewTransaction(0, ethCommon.Address{}, nil, 0, nil,
|
||||
data)
|
||||
}
|
||||
|
||||
@@ -372,7 +372,7 @@ func GenBids(nBids int, blocks []common.Block, coords []common.Coordinator) []co
|
||||
|
||||
// GenExitTree generates an exitTree (as an array of Exits)
|
||||
//nolint:gomnd
|
||||
func GenExitTree(n int, batches []common.Batch, accounts []common.Account) []common.ExitInfo {
|
||||
func GenExitTree(n int, batches []common.Batch, accounts []common.Account, blocks []common.Block) []common.ExitInfo {
|
||||
exitTree := make([]common.ExitInfo, n)
|
||||
for i := 0; i < n; i++ {
|
||||
exitTree[i] = common.ExitInfo{
|
||||
@@ -397,17 +397,14 @@ func GenExitTree(n int, batches []common.Batch, accounts []common.Account) []com
|
||||
Balance: big.NewInt(int64(i) * 1000),
|
||||
}
|
||||
if i%2 == 0 {
|
||||
instant := new(int64)
|
||||
*instant = int64(batches[(i+1)%len(batches)].BatchNum)
|
||||
exitTree[i].InstantWithdrawn = instant
|
||||
instant := int64(blocks[i%len(blocks)].EthBlockNum)
|
||||
exitTree[i].InstantWithdrawn = &instant
|
||||
} else if i%3 == 0 {
|
||||
delayedReq := new(int64)
|
||||
*delayedReq = int64(batches[(i+1)%len(batches)].BatchNum)
|
||||
exitTree[i].DelayedWithdrawRequest = delayedReq
|
||||
delayedReq := int64(blocks[i%len(blocks)].EthBlockNum)
|
||||
exitTree[i].DelayedWithdrawRequest = &delayedReq
|
||||
if i%9 == 0 {
|
||||
delayed := new(int64)
|
||||
*delayed = int64(batches[(i+2)%len(batches)].BatchNum)
|
||||
exitTree[i].DelayedWithdrawn = delayed
|
||||
delayed := int64(blocks[i%len(blocks)].EthBlockNum)
|
||||
exitTree[i].DelayedWithdrawn = &delayed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ type Context struct {
|
||||
Instructions []instruction
|
||||
userNames []string
|
||||
Users map[string]*User // Name -> *User
|
||||
usersByIdx map[int]*User
|
||||
UsersByIdx map[int]*User
|
||||
accountsByIdx map[int]*Account
|
||||
LastRegisteredTokenID common.TokenID
|
||||
l1CreatedAccounts map[string]*Account // (Name, TokenID) -> *Account
|
||||
@@ -81,7 +81,7 @@ func NewContext(rollupConstMaxL1UserTx int) *Context {
|
||||
return &Context{
|
||||
Users: make(map[string]*User),
|
||||
l1CreatedAccounts: make(map[string]*Account),
|
||||
usersByIdx: make(map[int]*User),
|
||||
UsersByIdx: make(map[int]*User),
|
||||
accountsByIdx: make(map[int]*Account),
|
||||
LastRegisteredTokenID: 0,
|
||||
|
||||
@@ -393,7 +393,7 @@ func (tc *Context) calculateIdxForL1Txs(isCoordinatorTxs bool, txs []L1Tx) error
|
||||
}
|
||||
tc.l1CreatedAccounts[idxTokenIDToString(tx.fromIdxName, tx.L1Tx.TokenID)] = tc.Users[tx.fromIdxName].Accounts[tx.L1Tx.TokenID]
|
||||
tc.accountsByIdx[tc.idx] = tc.Users[tx.fromIdxName].Accounts[tx.L1Tx.TokenID]
|
||||
tc.usersByIdx[tc.idx] = tc.Users[tx.fromIdxName]
|
||||
tc.UsersByIdx[tc.idx] = tc.Users[tx.fromIdxName]
|
||||
tc.idx++
|
||||
}
|
||||
if isCoordinatorTxs {
|
||||
@@ -745,7 +745,7 @@ func (tc *Context) FillBlocksExtra(blocks []common.BlockData, cfg *ConfigExtra)
|
||||
tx := &l1Txs[k]
|
||||
if tx.Type == common.TxTypeCreateAccountDeposit ||
|
||||
tx.Type == common.TxTypeCreateAccountDepositTransfer {
|
||||
user, ok := tc.usersByIdx[tc.extra.idx]
|
||||
user, ok := tc.UsersByIdx[tc.extra.idx]
|
||||
if !ok {
|
||||
return fmt.Errorf("Created account with idx: %v not found", tc.extra.idx)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user