From 40007cf9b900b6e8e8fae18a2beb663cff3c737f Mon Sep 17 00:00:00 2001 From: kaiden Date: Tue, 7 Jan 2025 17:45:47 +1100 Subject: [PATCH] rfct/til --- sequencer/test/til/lang.go | 68 +----- sequencer/test/til/lang_test.go | 14 +- sequencer/test/til/txs.go | 378 +------------------------------- sequencer/test/til/txs_test.go | 147 ++----------- 4 files changed, 40 insertions(+), 567 deletions(-) diff --git a/sequencer/test/til/lang.go b/sequencer/test/til/lang.go index bc5c86e..5a57d6d 100644 --- a/sequencer/test/til/lang.go +++ b/sequencer/test/til/lang.go @@ -7,7 +7,6 @@ import ( "io" "math/big" "sort" - "strconv" "tokamak-sybil-resistance/common" "tokamak-sybil-resistance/log" ) @@ -24,13 +23,6 @@ type setType string // SetTypeBlockchain defines the type 'Blockchain' of the set var SetTypeBlockchain = setType("Blockchain") -// SetTypePoolL2 defines the type 'PoolL2' of the set -var SetTypePoolL2 = setType("PoolL2") - -// TypeNewBatch is used for testing purposes only, and represents the -// common.TxType of a new batch -var TypeNewBatch common.TxType = "InstrTypeNewBatch" - // TypeNewBatchL1 is used for testing purposes only, and represents the // common.TxType of a new batch var TypeNewBatchL1 common.TxType = "InstrTypeNewBatchL1" @@ -56,9 +48,7 @@ type Instruction struct { To string Amount *big.Int DepositAmount *big.Int - Fee uint8 - // TokenID common.TokenID - Typ common.TxType // D: Deposit, T: Transfer, E: ForceExit + Typ common.TxType // D: Deposit, T: Transfer, E: ForceExit } // parsedSet contains the full Set of Instructions representing a full code @@ -84,12 +74,6 @@ func (i Instruction) String() string { if i.Typ != common.TxTypeDeposit { fmt.Fprintf(buf, "Amount: %d\n", i.Amount) } - // if i.Typ == common.TxTypeTransfer || - // i.Typ == common.TxTypeDepositTransfer || - // i.Typ == common.TxTypeCreateAccountDepositTransfer { - // fmt.Fprintf(buf, "Fee: %d, ", i.Fee) - // } - // fmt.Fprintf(buf, "TokenID: %d\n", i.TokenID) return buf.String() } @@ -97,7 +81,6 @@ func (i Instruction) String() string { func (i Instruction) raw() string { buf := bytes.NewBufferString("") fmt.Fprintf(buf, "%s", i.Typ) - // fmt.Fprintf(buf, "(%d)", i.TokenID) fmt.Fprintf(buf, "%s", i.From) if i.Typ == common.TxTypeCreateVouch || i.Typ == common.TxTypeDeleteVouch { @@ -264,14 +247,8 @@ func (p *parser) parseLine(setType setType) (*Instruction, error) { _, _ = p.s.r.ReadString('\n') return nil, errCommentLine } else if lit == ">" { - if setType == SetTypePoolL2 { - return c, common.Wrap(fmt.Errorf("unexpected '>' at PoolL2Txs set")) - } _, lit = p.scanIgnoreWhitespace() - if lit == "batch" { - _, _ = p.s.r.ReadString('\n') - return &Instruction{Typ: TypeNewBatch}, errNewEventLine - } else if lit == "batchL1" { + if lit == "batchL1" { _, _ = p.s.r.ReadString('\n') return &Instruction{Typ: TypeNewBatchL1}, errNewEventLine } else if lit == "block" { @@ -287,8 +264,6 @@ func (p *parser) parseLine(setType setType) (*Instruction, error) { _, lit = p.scanIgnoreWhitespace() if lit == "Blockchain" { return &Instruction{Typ: "Blockchain"}, errSetTypeLine - } else if lit == "PoolL2" { - return &Instruction{Typ: "PoolL2"}, errSetTypeLine } else { return c, common.Wrap(fmt.Errorf("invalid set type: '%s'. Valid set types: 'Blockchain', 'PoolL2'", lit)) @@ -299,7 +274,6 @@ func (p *parser) parseLine(setType setType) (*Instruction, error) { return c, common.Wrap(fmt.Errorf("set type not defined")) } vouch := false - fee := false if setType == SetTypeBlockchain { switch lit { @@ -318,17 +292,6 @@ func (p *parser) parseLine(setType setType) (*Instruction, error) { default: return c, common.Wrap(fmt.Errorf("unexpected Blockchain tx type: %s", lit)) } - } else if setType == SetTypePoolL2 { - switch lit { - case "PoolCreateVouch": - c.Typ = common.TxTypeCreateVouch - vouch = true - case "PoolDeleteVouch": - c.Typ = common.TxTypeDeleteVouch - vouch = true - default: - return c, common.Wrap(fmt.Errorf("unexpected PoolL2 tx type: %s", lit)) - } } else { return c, common.Wrap(fmt.Errorf("invalid set type: '%s'. Valid set types: 'Blockchain', 'PoolL2'", @@ -376,29 +339,6 @@ func (p *parser) parseLine(setType setType) (*Instruction, error) { } else { c.Amount = amount } - if fee { - if err := p.expectChar(c, "("); err != nil { - return c, common.Wrap(err) - } - _, lit = p.scanIgnoreWhitespace() - c.Literal += lit - fee, err := strconv.Atoi(lit) - if err != nil { - line, _ := p.s.r.ReadString('\n') - c.Literal += line - return c, common.Wrap(err) - } - if fee > common.MaxFeePlan-1 { - line, _ := p.s.r.ReadString('\n') - c.Literal += line - return c, common.Wrap(fmt.Errorf("fee %d can not be bigger than 255", fee)) - } - c.Fee = uint8(fee) - - if err := p.expectChar(c, ")"); err != nil { - return c, common.Wrap(err) - } - } if tok == EOF { return nil, common.Wrap(errof) @@ -436,9 +376,7 @@ func (p *parser) parse() (*parsedSet, error) { "there is already a previous instruction 'Type: %s' defined", i, instruction.Typ, ps.typ)) } - if instruction.Typ == "PoolL2" { - ps.typ = SetTypePoolL2 - } else if instruction.Typ == "Blockchain" { + if instruction.Typ == "Blockchain" { ps.typ = SetTypeBlockchain } else { log.Fatalf("line %d: Invalid set type: '%s'. Valid set types: "+ diff --git a/sequencer/test/til/lang_test.go b/sequencer/test/til/lang_test.go index ea984ed..3c3833c 100644 --- a/sequencer/test/til/lang_test.go +++ b/sequencer/test/til/lang_test.go @@ -19,14 +19,14 @@ func TestParseBlockchainTxs(t *testing.T) { CreateVouch A-B // set new batch - > batch + > batchL1 CreateAccountDeposit C: 5 CreateVouch B-C Deposit User0: 20 Deposit User1: 20 - > batch + > batchL1 > block DeleteVouch A-B @@ -44,7 +44,7 @@ func TestParseBlockchainTxs(t *testing.T) { } } - assert.Equal(t, TypeNewBatch, instructions.instructions[4].Typ) + assert.Equal(t, TypeNewBatchL1, instructions.instructions[4].Typ) assert.Equal(t, "DepositUser0:20", instructions.instructions[7].raw()) assert.Equal(t, "CreateVouchA-B", instructions.instructions[3].raw()) assert.Equal(t, "DeleteVouchA-B", instructions.instructions[11].raw()) @@ -97,12 +97,4 @@ func TestParseErrors(t *testing.T) { assert.Equal(t, "line 1: Type:, err: invalid set type: 'PoolL1'. Valid set types: 'Blockchain', 'PoolL2'", err.Error()) - - s = `Type: PoolL2 - Type: Blockchain` - parser = newParser(strings.NewReader(s)) - _, err = parser.parse() - assert.Equal(t, - "line 2: Instruction of 'Type: Blockchain' when there is already a previous "+ - "instruction 'Type: PoolL2' defined", err.Error()) } diff --git a/sequencer/test/til/txs.go b/sequencer/test/til/txs.go index 0e33831..88e1be4 100644 --- a/sequencer/test/til/txs.go +++ b/sequencer/test/til/txs.go @@ -16,7 +16,6 @@ import ( func newBatchData(batchNum int) common.BatchData { return common.BatchData{ - // L1CoordinatorTxs: []common.L1Tx{}, Batch: common.Batch{ BatchNum: common.BatchNum(batchNum), @@ -24,7 +23,6 @@ func newBatchData(batchNum int) common.BatchData { VouchRoot: big.NewInt(0), ScoreRoot: big.NewInt(0), ExitRoot: big.NewInt(0), - // CollectedFees: make(map[common.TokenID]*big.Int), }, } } @@ -69,10 +67,7 @@ type Context struct { Queues [][]L1Tx ToForgeNum int openToForge int - // currBatchTest struct { - // l1CoordinatorTxs []L1Tx - // } - blockNum int64 + blockNum int64 extra contextExtra } @@ -81,17 +76,16 @@ type Context struct { func NewContext(chainID uint64, rollupConstMaxL1UserTx int) *Context { currBatchNum := 1 // The protocol defines the first batchNum to be 1 return &Context{ - Accounts: make(map[string]*Account), - l1CreatedAccounts: make(map[string]*Account), - AccountsByIdx: make(map[int]*Account), - LastRegisteredTokenID: 0, + Accounts: make(map[string]*Account), + l1CreatedAccounts: make(map[string]*Account), + AccountsByIdx: make(map[int]*Account), rollupConstMaxL1UserTx: rollupConstMaxL1UserTx, chainID: chainID, idx: common.UserThreshold, // We use some placeholder values for StateRoot and ExitTree // because these values will never be nil - currBlock: newBlock(2), //nolint:gomnd + currBlock: newBlock(2), currBatch: newBatchData(currBatchNum), currBatchNum: currBatchNum, // start with 2 queues, one for toForge, and the other for openToForge @@ -157,20 +151,13 @@ func (tc *Context) GenerateBlocksFromInstructions(set []Instruction) ([]common.B accountNames := []string{} addedNames := make(map[string]bool) for _, inst := range set { - // TODO: hermez doesn't have `inst.From != ""` condition but without it + // TODO: sybil doesn't have `inst.From != ""` condition but without it // empty string gets added to the accountNames if _, ok := addedNames[inst.From]; !ok && inst.From != "" { // If the name wasn't already added accountNames = append(accountNames, inst.From) addedNames[inst.From] = true } - - // Only when the instruction is a transfer type - // if _, ok := addedNames[inst.To]; !ok { - // // If the name wasn't already added - // accountNames = append(accountNames, inst.To) - // addedNames[inst.To] = true - // } } tc.accountNames = accountNames tc.instructions = set @@ -183,7 +170,6 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) { var blocks []common.BlockData for _, inst := range tc.instructions { switch inst.Typ { - //Removed case for TxTypeCreateAccountDepositTransfer case common.TxTypeCreateAccountDeposit: // tx source: L1UserTx tx := common.L1Tx{ @@ -208,7 +194,6 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) { return nil, common.Wrap(fmt.Errorf("line %d: %s", inst.LineNum, err.Error())) } tx := common.L1Tx{ - // TokenID: inst.TokenID, DepositAmount: inst.DepositAmount, Type: inst.Typ, } @@ -221,21 +206,6 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) { return nil, common.Wrap(err) } case common.TxTypeCreateVouch: - // tx := common.L2Tx{ - // Amount: big.NewInt(0), - // // Fee: common.FeeSelector(inst.Fee), - // Type: common.TxTypeCreateVouch, - // EthBlockNum: tc.blockNum, - // } - // // when converted to PoolL2Tx BatchNum parameter is lost - // tx.BatchNum = common.BatchNum(tc.currBatchNum) - // testTx := L2Tx{ - // lineNum: inst.LineNum, - // fromIdxName: inst.From, - // toIdxName: inst.To, - // L2Tx: tx, - // } - // tc.currBatchTest.l2Txs = append(tc.currBatchTest.l2Txs, testTx) tx := common.L1Tx{ Amount: big.NewInt(0), DepositAmount: big.NewInt(0), @@ -251,21 +221,6 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) { return nil, common.Wrap(err) } case common.TxTypeDeleteVouch: - // tx := common.L2Tx{ - // Amount: big.NewInt(0), - // // Fee: common.FeeSelector(inst.Fee), - // Type: common.TxTypeDeleteVouch, - // EthBlockNum: tc.blockNum, - // } - // // when converted to PoolL2Tx BatchNum parameter is lost - // tx.BatchNum = common.BatchNum(tc.currBatchNum) - // testTx := L2Tx{ - // lineNum: inst.LineNum, - // fromIdxName: inst.From, - // toIdxName: inst.To, - // L2Tx: tx, - // } - // tc.currBatchTest.l2Txs = append(tc.currBatchTest.l2Txs, testTx) tx := common.L1Tx{ Amount: big.NewInt(0), DepositAmount: big.NewInt(0), @@ -282,8 +237,7 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) { } case common.TxTypeForceExit: // tx source: L1UserTx tx := common.L1Tx{ - ToIdx: common.AccountIdx(1), // as is an Exit - // TokenID: inst.TokenID, + ToIdx: common.AccountIdx(1), // as is an Exit Amount: inst.Amount, DepositAmount: big.NewInt(0), Type: common.TxTypeForceExit, @@ -297,32 +251,6 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) { if err := tc.addToL1UserQueue(testTx); err != nil { return nil, common.Wrap(err) } - // case common.TxTypeExit: // tx source: L2Tx - // tx := common.L2Tx{ - // ToIdx: common.AccountIdx(1), // as is an Exit - // Amount: inst.Amount, - // Type: common.TxTypeExit, - // EthBlockNum: tc.blockNum, - // } - // // when converted to PoolL2Tx BatchNum parameter is lost - // tx.BatchNum = common.BatchNum(tc.currBatchNum) - // testTx := L2Tx{ - // lineNum: inst.LineNum, - // fromIdxName: inst.From, - // toIdxName: inst.To, - // L2Tx: tx, - // } - // tc.currBatchTest.l2Txs = append(tc.currBatchTest.l2Txs, testTx) - // case TypeNewBatch: - // for _, tx := range tc.currBatchTest.l1CoordinatorTxs { - // tc.l1CreatedAccounts[tx.fromIdxName] = tc.Accounts[tx.fromIdxName] - // tc.AccountsByIdx[tc.idx] = tc.Accounts[tx.fromIdxName] - // tc.idx++ - // } - // if err := tc.setIdxs(); err != nil { - // log.Error(err) - // return nil, common.Wrap(err) - // } case TypeNewBatchL1: // for each L1UserTx of the Queues[ToForgeNum], accumulate Txs into map for _, tx := range tc.Queues[tc.ToForgeNum] { @@ -330,13 +258,8 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) { tc.AccountsByIdx[tc.idx] = tc.Accounts[tx.fromIdxName] tc.idx++ } - // for _, tx := range tc.currBatchTest.l1CoordinatorTxs { - // tc.l1CreatedAccounts[tx.fromIdxName] = tc.Accounts[tx.fromIdxName] - // tc.AccountsByIdx[tc.idx] = tc.Accounts[tx.fromIdxName] - // tc.idx++ - // } tc.currBatch.L1Batch = true - if err := tc.setIdxs(); err != nil { + if err := tc.setCurrBatch(); err != nil { return nil, common.Wrap(err) } toForgeL1TxsNum := int64(tc.openToForge) @@ -360,52 +283,12 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) { return blocks, nil } -// setIdxs sets the Idxs to the transactions of the tc.currBatch -func (tc *Context) setIdxs() error { - // once Idxs are calculated, update transactions to use the new Idxs - // for i := 0; i < len(tc.currBatchTest.l2Txs); i++ { - // testTx := &tc.currBatchTest.l2Txs[i] - - // if tc.Accounts[testTx.fromIdxName] == nil { - // return common.Wrap(fmt.Errorf("line %d: %s from User %s "+ - // "while account not created yet", - // testTx.lineNum, testTx.L2Tx.Type, testTx.fromIdxName)) - // } - // if testTx.L2Tx.Type == common.TxTypeCreateVouch || testTx.L2Tx.Type == common.TxTypeDeleteVouch { - // if _, ok := tc.Accounts[testTx.toIdxName]; !ok { - // return common.Wrap(fmt.Errorf("line %d: Can not Voute for a non "+ - // "existing account. Batch %d, ToIdx name: %s", - // testTx.lineNum, tc.currBatchNum, testTx.toIdxName)) - // } - // } - // tc.Accounts[testTx.fromIdxName].Nonce++ - // // next line is commented to avoid Blockchain L2Txs to have - // // Nonce different from 0, as from Blockchain those - // // transactions will come without Nonce - // // testTx.L2Tx.Nonce = tc.Users[testTx.fromIdxName].Accounts[testTx.tokenID].Nonce - - // // set real Idx - // testTx.L2Tx.FromIdx = tc.Accounts[testTx.fromIdxName].Idx - // if testTx.L2Tx.Type == common.TxTypeCreateVouch || testTx.L2Tx.Type == common.TxTypeDeleteVouch { - // testTx.L2Tx.ToIdx = tc.Accounts[testTx.toIdxName].Idx - // } - // // in case Type==Exit, ToIdx=1, already set at the - // // GenerateBlocks main switch inside TxTypeExit case - // nTx, err := common.NewL2Tx(&testTx.L2Tx) - // if err != nil { - // return common.Wrap(fmt.Errorf("line %d: %s", testTx.lineNum, err.Error())) - // } - // testTx.L2Tx = *nTx - - // tc.currBatch.L2Txs = append(tc.currBatch.L2Txs, testTx.L2Tx) - // } - +// setCurrBatch sets the Idxs to the transactions of the tc.currBatch +func (tc *Context) setCurrBatch() error { tc.currBatch.Batch.LastIdx = int64(tc.idx - 1) // `-1` because tc.idx is the next available idx tc.currBlock.Rollup.Batches = append(tc.currBlock.Rollup.Batches, tc.currBatch) tc.currBatchNum++ tc.currBatch = newBatchData(tc.currBatchNum) - // tc.currBatchTest.l1CoordinatorTxs = nil - // tc.currBatchTest.l2Txs = nil return nil } @@ -464,136 +347,6 @@ func (tc *Context) checkIfAccountExists(tf string, inst Instruction) error { return nil } -// GeneratePoolL2Txs returns an array of common.PoolL2Tx from a given set made -// of a string. It uses the users (keys) of the Context. -// func (tc *Context) GeneratePoolL2Txs(set string) ([]common.PoolL2Tx, error) { -// parser := newParser(strings.NewReader(set)) -// parsedSet, err := parser.parse() -// if err != nil { -// return nil, common.Wrap(err) -// } -// if parsedSet.typ != SetTypePoolL2 { -// return nil, common.Wrap(fmt.Errorf("expected set type: %s, found: %s", -// SetTypePoolL2, parsedSet.typ)) -// } - -// tc.instructions = parsedSet.instructions -// tc.accountNames = parsedSet.users - -// return tc.generatePoolL2Txs() -// } - -// GeneratePoolL2TxsFromInstructions returns an array of common.PoolL2Tx from a -// given set made of instructions. It uses the users (keys) of the Context. -// func (tc *Context) GeneratePoolL2TxsFromInstructions(set []Instruction) ([]common.PoolL2Tx, error) { -// userNames := []string{} -// addedNames := make(map[string]bool) -// for _, inst := range set { -// if _, ok := addedNames[inst.From]; !ok { -// // If the name wasn't already added -// userNames = append(userNames, inst.From) -// addedNames[inst.From] = true -// } -// if _, ok := addedNames[inst.To]; !ok { -// // If the name wasn't already added -// userNames = append(userNames, inst.To) -// addedNames[inst.To] = true -// } -// } -// tc.userNames = userNames -// tc.instructions = set - -// return tc.generatePoolL2Txs() -// } - -// func (tc *Context) generatePoolL2Txs() ([]common.PoolL2Tx, error) { -// tc.generateKeys(tc.accountNames) - -// txs := []common.PoolL2Tx{} -// for _, inst := range tc.instructions { -// switch inst.Typ { -// case common.TxTypeCreateVouch, common.TxTypeDeleteVouch: -// if err := tc.checkIfAccountExists(inst.From, inst); err != nil { -// log.Error(err) -// return nil, common.Wrap(fmt.Errorf("line %d: %s", inst.LineNum, err.Error())) -// } -// // if inst.Typ == common.TxTypeTransfer { -// // // if TxTypeTransfer, need to exist the ToIdx account -// // if err := tc.checkIfAccountExists(inst.To, inst); err != nil { -// // log.Error(err) -// // return nil, common.Wrap(fmt.Errorf("Line %d: %s", inst.LineNum, err.Error())) -// // } -// // } -// // if account of receiver does not exist, don't use -// // ToIdx, and use only ToEthAddr & ToBJJ -// tx := common.PoolL2Tx{ -// FromIdx: tc.Accounts[inst.From].Idx, -// Amount: big.NewInt(0), -// Fee: common.FeeSelector(inst.Fee), -// Nonce: tc.Accounts[inst.From].Nonce, -// State: common.PoolL2TxStatePending, -// Timestamp: time.Now(), -// RqToEthAddr: common.EmptyAddr, -// RqToBJJ: common.EmptyBJJComp, -// Type: inst.Typ, -// } -// tc.Accounts[inst.From].Nonce++ -// if tx.Type == common.TxTypeCreateVouch || tx.Type == common.TxTypeDeleteVouch { -// tx.ToIdx = tc.Accounts[inst.To].Idx -// tx.ToEthAddr = common.EmptyAddr -// tx.ToBJJ = common.EmptyBJJComp -// } -// nTx, err := common.NewPoolL2Tx(&tx) -// if err != nil { -// return nil, common.Wrap(fmt.Errorf("line %d: %s", inst.LineNum, err.Error())) -// } -// tx = *nTx -// // perform signature and set it to tx.Signature -// toSign, err := tx.HashToSign(tc.chainID) -// if err != nil { -// return nil, common.Wrap(fmt.Errorf("line %d: %s", inst.LineNum, err.Error())) -// } -// sig := tc.Accounts[inst.From].BJJ.SignPoseidon(toSign) -// tx.Signature = sig.Compress() - -// txs = append(txs, tx) - -// case common.TxTypeExit: -// tx := common.PoolL2Tx{ -// FromIdx: tc.Accounts[inst.From].Idx, -// ToIdx: common.AccountIdx(1), // as is an Exit -// Fee: common.FeeSelector(inst.Fee), -// Amount: inst.Amount, -// ToEthAddr: common.EmptyAddr, -// ToBJJ: common.EmptyBJJComp, -// Nonce: tc.Accounts[inst.From].Nonce, -// State: common.PoolL2TxStatePending, -// Type: common.TxTypeExit, -// } -// tc.Accounts[inst.From].Nonce++ -// nTx, err := common.NewPoolL2Tx(&tx) -// if err != nil { -// return nil, common.Wrap(fmt.Errorf("line %d: %s", inst.LineNum, err.Error())) -// } -// tx = *nTx -// // perform signature and set it to tx.Signature -// toSign, err := tx.HashToSign(tc.chainID) -// if err != nil { -// return nil, common.Wrap(fmt.Errorf("line %d: %s", inst.LineNum, err.Error())) -// } -// sig := tc.Accounts[inst.From].BJJ.SignPoseidon(toSign) -// tx.Signature = sig.Compress() -// txs = append(txs, tx) -// default: -// return nil, -// common.Wrap(fmt.Errorf("line %d: instruction type unrecognized: %s", -// inst.LineNum, inst.Typ)) -// } -// } - -// return txs, nil -// } - // RestartNonces sets all the Users.Accounts.Nonces to 0 func (tc *Context) RestartNonces() { for name := range tc.Accounts { @@ -640,8 +393,6 @@ func NewUser(keyDerivationIndex int, name string) Account { // Nonce nonce := common.Nonce(0) - // BatchNum - return Account{ Name: name, Idx: idx, @@ -650,9 +401,6 @@ func NewUser(keyDerivationIndex int, name string) Account { Balance: balance, Nonce: nonce, BatchNum: keyDerivationIndex, - - // EthSk: &key, - // Accounts: make(map[common.TokenID]*Account), } } @@ -746,21 +494,8 @@ func (tc *Context) FillBlocksForgedL1UserTxs(blocks []common.BlockData) error { // - blocks[].Rollup.Batch.EthBlockNum // - blocks[].Rollup.Batch.ForgerAddr // - blocks[].Rollup.Batch.ForgeL1TxsNum -// - blocks[].Rollup.Batch.L1CoordinatorTxs[].TxID -// - blocks[].Rollup.Batch.L1CoordinatorTxs[].BatchNum -// - blocks[].Rollup.Batch.L1CoordinatorTxs[].EthBlockNum -// - blocks[].Rollup.Batch.L1CoordinatorTxs[].Position -// - blocks[].Rollup.Batch.L1CoordinatorTxs[].EffectiveAmount -// - blocks[].Rollup.Batch.L1CoordinatorTxs[].EffectiveDepositAmount -// - blocks[].Rollup.Batch.L1CoordinatorTxs[].EffectiveFromIdx -// - blocks[].Rollup.Batch.L2Txs[].TxID -// - blocks[].Rollup.Batch.L2Txs[].Position -// - blocks[].Rollup.Batch.L2Txs[].Nonce -// - blocks[].Rollup.Batch.L2Txs[].TokenID // - blocks[].Rollup.Batch.ExitTree // - blocks[].Rollup.Batch.CreatedAccounts -// - blocks[].Rollup.Batch.FeeIdxCoordinator -// - blocks[].Rollup.Batch.CollectedFees func (tc *Context) FillBlocksExtra(blocks []common.BlockData, cfg *ConfigExtra) error { // Fill extra fields not generated by til in til block for i := range blocks { @@ -777,13 +512,6 @@ func (tc *Context) FillBlocksExtra(blocks []common.BlockData, cfg *ConfigExtra) tc.extra.toForgeL1TxsNum++ } - // batchNum := batch.Batch.BatchNum - // for k := range batch.L1CoordinatorTxs { - // tx := &batch.L1CoordinatorTxs[k] - // tx.BatchNum = &batchNum - // tx.EthBlockNum = batch.Batch.EthBlockNum - // } - // TODO: default value is nil but the db column type is not nullable batch.Batch.GasPrice = big.NewInt(0) } @@ -800,13 +528,9 @@ func (tc *Context) FillBlocksExtra(blocks []common.BlockData, cfg *ConfigExtra) l1Txs = append(l1Txs, &tc.Queues[*batch.Batch.ForgeL1TxsNum][k].L1Tx) } } - // for k := range batch.L1CoordinatorTxs { - // l1Txs = append(l1Txs, &batch.L1CoordinatorTxs[k]) - // } for k := range l1Txs { tx := l1Txs[k] if tx.Type == common.TxTypeCreateAccountDeposit { - // tx.Type == common.TxTypeCreateAccountDepositTransfer { user, ok := tc.AccountsByIdx[tc.extra.idx] if !ok { return common.Wrap(fmt.Errorf("created account with idx: %v not found", tc.extra.idx)) @@ -830,46 +554,6 @@ func (tc *Context) FillBlocksExtra(blocks []common.BlockData, cfg *ConfigExtra) } } - // Fill expected positions in L1CoordinatorTxs and L2Txs - // for i := range blocks { - // block := &blocks[i] - // for j := range block.Rollup.Batches { - // batch := &block.Rollup.Batches[j] - // position := 0 - // if batch.L1Batch { - // position = len(tc.Queues[*batch.Batch.ForgeL1TxsNum]) - // } - // for k := range batch.L1CoordinatorTxs { - // tx := &batch.L1CoordinatorTxs[k] - // tx.Position = position - // position++ - // tx.EffectiveAmount = big.NewInt(0) - // tx.EffectiveDepositAmount = big.NewInt(0) - // nTx, err := common.NewL1Tx(tx) - // if err != nil { - // return common.Wrap(err) - // } - // *tx = *nTx - // } - // for k := range batch.L2Txs { - // tx := &batch.L2Txs[k] - // tx.Position = position - // position++ - // tx.Nonce = tc.extra.nonces[tx.FromIdx] - // // tx.TokenID = tc.AccountsByIdx[int(tx.FromIdx)].TokenID - // tc.extra.nonces[tx.FromIdx]++ - // if err := tx.SetID(); err != nil { - // return common.Wrap(err) - // } - // nTx, err := common.NewL2Tx(tx) - // if err != nil { - // return common.Wrap(err) - // } - // *tx = *nTx - // } - // } - // } - // Fill ExitTree (only AccountIdx and Balance) for i := range blocks { block := &blocks[i] @@ -889,48 +573,6 @@ func (tc *Context) FillBlocksExtra(blocks []common.BlockData, cfg *ConfigExtra) } } } - // for k := range batch.L2Txs { - // tx := &batch.L2Txs[k] - // if tx.Type == common.TxTypeExit { - // batch.ExitTree = append(batch.ExitTree, common.ExitInfo{ - // BatchNum: batch.Batch.BatchNum, - // AccountIdx: tx.FromIdx, - // Balance: tx.Amount, - // }) - // } - // fee, err := common.CalcFeeAmount(tx.Amount, tx.Fee) - // if err != nil { - // return common.Wrap(err) - // } - - // fromAcc, ok := tc.AccountsByIdx[int(tx.FromIdx)] - // if !ok { - // return common.Wrap(fmt.Errorf("L2tx.FromIdx idx: %v not found", tx.FromIdx)) - // } - - // Find the idx of the CoordUser for the - // TokenID, and if it exists, add the fee to - // the collectedFees. Only consider the - // coordinator account to receive fee if it was - // created in this or a previous batch - // if acc, ok := tc.l1CreatedAccounts[cfg.CoordUser]; ok && - // common.BatchNum(acc.BatchNum) <= batch.Batch.BatchNum { - // found := false - // for _, idx := range batch.Batch.FeeIdxsCoordinator { - // if idx == common.AccountIdx(acc.Idx) { - // found = true - // break - // } - // } - // // if !found { - // // batch.Batch.FeeIdxsCoordinator = append(batch.Batch.FeeIdxsCoordinator, - // // common.AccountIdx(acc.Idx)) - // // batch.Batch.CollectedFees[fromAcc.TokenID] = big.NewInt(0) - // // } - // // collected := batch.Batch.CollectedFees[fromAcc.TokenID] - // // collected.Add(collected, fee) - // } - // } } } return nil diff --git a/sequencer/test/til/txs_test.go b/sequencer/test/til/txs_test.go index 3911c62..cc278c7 100644 --- a/sequencer/test/til/txs_test.go +++ b/sequencer/test/til/txs_test.go @@ -144,60 +144,6 @@ func (tc *Context) checkL1TxParams(t *testing.T, tx common.L1Tx, typ common.TxTy } } -// func (tc *Context) checkL2TxParams(t *testing.T, tx common.L2Tx, typ common.TxType, -// from, to string, amount *big.Int, batchNum common.BatchNum) { -// assert.Equal(t, typ, tx.Type) -// assert.Equal(t, tc.Accounts[from].Idx, tx.FromIdx) -// if tx.Type != common.TxTypeExit { -// assert.Equal(t, tc.Accounts[to].Idx, tx.ToIdx) -// } -// if amount != nil { -// assert.Equal(t, amount, tx.Amount) -// } -// assert.Equal(t, batchNum, tx.BatchNum) -// } - -// func TestGeneratePoolL2Txs(t *testing.T) { -// set := ` -// Type: Blockchain -// CreateAccountDeposit A: 10 -// CreateAccountDeposit C: 5 -// CreateAccountDeposit B: 5 -// CreateAccountDeposit D: 0 -// > batchL1 -// > batchL1 -// ` -// tc := NewContext(0, common.RollupConstMaxL1UserTx) -// _, err := tc.GenerateBlocks(set) -// require.NoError(t, err) -// set = ` -// Type: PoolL2 -// PoolCreateVouch A-B -// PoolCreateVouch A-C -// PoolDeleteVouch A-C -// PoolExit A: 3 -// ` -// poolL2Txs, err := tc.GeneratePoolL2Txs(set) -// require.NoError(t, err) -// assert.Equal(t, 4, len(poolL2Txs)) -// assert.Equal(t, common.TxTypeCreateVouch, poolL2Txs[0].Type) -// assert.Equal(t, common.TxTypeDeleteVouch, poolL2Txs[2].Type) -// assert.Equal(t, common.TxTypeExit, poolL2Txs[3].Type) -// assert.Equal(t, common.Nonce(0), poolL2Txs[0].Nonce) -// assert.Equal(t, common.Nonce(1), poolL2Txs[1].Nonce) -// assert.Equal(t, common.Nonce(2), poolL2Txs[2].Nonce) -// assert.Equal(t, common.Nonce(3), poolL2Txs[3].Nonce) - -// // load another set in the same Context -// set = ` -// Type: PoolL2 -// PoolExit B: 3 -// ` -// poolL2Txs, err = tc.GeneratePoolL2Txs(set) -// require.NoError(t, err) -// assert.Equal(t, common.Nonce(0), poolL2Txs[0].Nonce) -// } - func TestGenerateErrors(t *testing.T) { // check transactions when account is not created yet set := ` @@ -253,33 +199,6 @@ func TestGenerateErrors(t *testing.T) { tc = NewContext(0, common.RollupConstMaxL1UserTx) _, err = tc.GenerateBlocks(set) require.Equal(t, "line 2: CreateVouchA-, err: expected 'to' account name, found ''", err.Error()) - - // // check vouching syntax errors on L2 - // set = ` - // Type: PoolL2 - // DeleteVouch A - // > batch - // ` - // tc = NewContext(0, common.RollupConstMaxL1UserTx) - // _, err = tc.GenerateBlocks(set) - // require.Equal(t, "line 2: DeleteVouch, err: unexpected PoolL2 tx type: DeleteVouch", err.Error()) - - // set = ` - // Type: PoolL2 - // PoolCreateVouch A - // > batch - // ` - // tc = NewContext(0, common.RollupConstMaxL1UserTx) - // _, err = tc.GenerateBlocks(set) - // require.Equal(t, "line 2: PoolCreateVouchA> batch\n, err: expected '-', found '>'", err.Error()) - - // set = ` - // Type: PoolL2 - // PoolDeleteVouch A- - // ` - // tc = NewContext(0, common.RollupConstMaxL1UserTx) - // _, err = tc.GenerateBlocks(set) - // require.Equal(t, "line 2: PoolDeleteVouchA-, err: expected 'to' account name, found ''", err.Error()) } func TestGenerateBlocksFromInstructions(t *testing.T) { @@ -289,8 +208,8 @@ func TestGenerateBlocksFromInstructions(t *testing.T) { i := 0 da := big.NewInt(10) setInst = append(setInst, Instruction{ - LineNum: i, - // Literal: "CreateAccountDeposit A: 10", + LineNum: i, + Literal: "CreateAccountDeposit A: 10", Typ: common.TxTypeCreateAccountDeposit, From: "A", DepositAmount: da, @@ -299,8 +218,8 @@ func TestGenerateBlocksFromInstructions(t *testing.T) { i++ da = big.NewInt(10) setInst = append(setInst, Instruction{ - LineNum: i, - // Literal: "CreateAccountDeposit B: 10", + LineNum: i, + Literal: "CreateAccountDeposit B: 10", Typ: common.TxTypeCreateAccountDeposit, From: "B", DepositAmount: da, @@ -309,8 +228,8 @@ func TestGenerateBlocksFromInstructions(t *testing.T) { i++ da = big.NewInt(6) setInst = append(setInst, Instruction{ - LineNum: i, - // Literal: "Deposit A: 6", + LineNum: i, + Literal: "Deposit A: 6", Typ: common.TxTypeDeposit, From: "A", DepositAmount: da, @@ -319,60 +238,49 @@ func TestGenerateBlocksFromInstructions(t *testing.T) { i++ setInst = append(setInst, Instruction{ LineNum: i, - // Literal: "CreateVouch A-B", - Typ: common.TxTypeCreateVouch, - From: "A", - To: "B", + Literal: "CreateVouch A-B", + Typ: common.TxTypeCreateVouch, + From: "A", + To: "B", }) i++ setInst = append(setInst, Instruction{ LineNum: i, - // Literal: "CreateVouch B-A", - Typ: common.TxTypeCreateVouch, - From: "B", - To: "A", + Literal: "CreateVouch B-A", + Typ: common.TxTypeCreateVouch, + From: "B", + To: "A", }) i++ setInst = append(setInst, Instruction{ LineNum: i, - // Literal: "> batchL1", - Typ: TypeNewBatchL1, + Literal: "> batchL1", + Typ: TypeNewBatchL1, }) - // i++ - // a := big.NewInt(3) - // setInst = append(setInst, Instruction{ - // LineNum: i, - // // Literal: "Exit A: 3", - // Typ: common.TxTypeExit, - // From: "A", - // Amount: a, - // Fee: 1, - // }) - i++ setInst = append(setInst, Instruction{ LineNum: i, - // Literal: "DeleteVouch A-B", - Typ: common.TxTypeDeleteVouch, - From: "A", - To: "B", + Literal: "DeleteVouch A-B", + Typ: common.TxTypeDeleteVouch, + From: "A", + To: "B", }) i++ setInst = append(setInst, Instruction{ LineNum: i, - // Literal: "> batch", - Typ: TypeNewBatchL1, + Literal: "> batchL1", + Typ: TypeNewBatchL1, }) i++ setInst = append(setInst, Instruction{ LineNum: i, - // Literal: "> block", - Typ: TypeNewBlock, + Literal: "> block", + Typ: TypeNewBlock, }) tc := NewContext(0, common.RollupConstMaxL1UserTx) @@ -399,13 +307,6 @@ func TestGenerateBlocksFromInstructions(t *testing.T) { // Generated data should be equivalent, except for Eth Addrs and BJJs for i, strBatch := range blockFromString[0].Rollup.Batches { - // instBatch := blockFromInstructions[0].Rollup.Batches[i] - // for j := 0; j < len(strBatch.L1CoordinatorTxs); j++ { - // blockFromInstructions[0].Rollup.Batches[i].L1CoordinatorTxs[j].FromEthAddr = - // blockFromString[0].Rollup.Batches[i].L1CoordinatorTxs[j].FromEthAddr - // blockFromInstructions[0].Rollup.Batches[i].L1CoordinatorTxs[j].FromBJJ = - // blockFromString[0].Rollup.Batches[i].L1CoordinatorTxs[j].FromBJJ - // } for j := 0; j < len(strBatch.L1UserTxs); j++ { blockFromInstructions[0].Rollup.Batches[i].L1UserTxs[j].FromEthAddr = blockFromString[0].Rollup.Batches[i].L1UserTxs[j].FromEthAddr