@@ -176,6 +176,62 @@ func (d *Depositor) SendAndMine(ctx context.Context, offset, nvals int, batch ty
176176 return nil
177177}
178178
179+ // SendAndMineByBatch uses the deterministic validator generator to generate deposits for `nvals` (number of validators).
180+ // To control which validators should receive deposits, so that we can generate deposits at different stages of e2e,
181+ // the `offset` parameter skips the first N validators in the deterministic list.
182+ // In order to test the requirement that our deposit follower is able to handle multiple partial deposits,
183+ // the `partial` flag specifies that half of the deposits should be broken up into 2 transactions.
184+ // Once the set of deposits has been generated, it submits a transaction for each deposit
185+ // (using 2 transactions for partial deposits) and then uses WaitForBlocks to send these transactions by one batch per block.
186+ // The batch size is determined by the provided batch size provided as an argument.
187+ func (d * Depositor ) SendAndMineByBatch (ctx context.Context , offset , nvals , batchSize int , batch types.DepositBatch , partial bool ) error {
188+ balance , err := d .Client .BalanceAt (ctx , d .Key .Address , nil )
189+ if err != nil {
190+ return err
191+ }
192+ // This is the "Send" part of the function. Compute deposits for `nvals` validators,
193+ // with half of those deposits being split over 2 transactions if the `partial` flag is true,
194+ // and throwing away any validators before `offset`.
195+ deposits , err := computeDeposits (offset , nvals , partial )
196+ if err != nil {
197+ return err
198+ }
199+ numBatch := len (deposits ) / batchSize
200+ log .WithField ("numDeposits" , len (deposits )).WithField ("batchSize" , batchSize ).WithField ("numBatches" , numBatch ).WithField ("balance" , balance .String ()).WithField ("account" , d .Key .Address .Hex ()).Info ("SendAndMineByBatch check" )
201+ for i := 0 ; i < numBatch ; i ++ {
202+ txo , err := d .txops (ctx )
203+ if err != nil {
204+ return err
205+ }
206+ for _ , dd := range deposits [i * batchSize : (i + 1 )* batchSize ] {
207+ if err := d .SendDeposit (dd , txo , batch ); err != nil {
208+ return err
209+ }
210+ }
211+ // This is the "AndMine" part of the function. WaitForBlocks will spam transactions to/from the given key
212+ // to advance the EL chain and until the chain has advanced the requested amount.
213+ if err = WaitForBlocks (d .Client , d .Key , 1 ); err != nil {
214+ return fmt .Errorf ("failed to mine blocks %w" , err )
215+ }
216+ }
217+ txo , err := d .txops (ctx )
218+ if err != nil {
219+ return err
220+ }
221+ // Send out the last partial batch
222+ for _ , dd := range deposits [numBatch * batchSize :] {
223+ if err := d .SendDeposit (dd , txo , batch ); err != nil {
224+ return err
225+ }
226+ }
227+ // This is the "AndMine" part of the function. WaitForBlocks will spam transactions to/from the given key
228+ // to advance the EL chain and until the chain has advanced the requested amount.
229+ if err = WaitForBlocks (d .Client , d .Key , 1 ); err != nil {
230+ return fmt .Errorf ("failed to mine blocks %w" , err )
231+ }
232+ return nil
233+ }
234+
179235// SendDeposit sends a single deposit. A record of this deposit will be tracked for the life of the Depositor,
180236// allowing evaluators to use the deposit history to make assertions about those deposits.
181237func (d * Depositor ) SendDeposit (dep * eth.Deposit , txo * bind.TransactOpts , batch types.DepositBatch ) error {
0 commit comments