Repository navigation
Expand file tree
/
Copy pathmain.go
More file actions
568 lines (503 loc) · 19.2 KB
/
Copy pathmain.go
File metadata and controls
568 lines (503 loc) · 19.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
package main
import (
"context"
"errors"
"flag"
"fmt"
"math/big"
"os"
"strings"
"time"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum-optimism/optimism/op-node/bindings"
bindingspreview "github.com/ethereum-optimism/optimism/op-node/bindings/preview"
oplog "github.com/ethereum-optimism/optimism/op-service/log"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/rpc"
withdrawerbindings "github.com/base/withdrawer/bindings"
"github.com/base/withdrawer/signer"
"github.com/base/withdrawer/withdraw"
)
type network struct {
l2RPC string
portalAddress string
l2OOAddress string
disputeGameFactory string
anchorStateRegistry string
faultProofs bool
}
// GasConfig holds gas-related configuration for transactions
type GasConfig struct {
GasLimit uint64 // Override automatic gas estimation
GasPrice *big.Int // Legacy transaction gas price
MaxFeePerGas *big.Int // EIP-1559 max fee per gas
MaxPriorityFee *big.Int // EIP-1559 max priority fee
GasMultiplier float64 // Multiplier for estimated gas (default 1.0)
MaxGasPrice *big.Int // Safety cap on gas price
}
var networks = map[string]network{
"base-mainnet": {
l2RPC: "https://mainnet.base.org",
portalAddress: "0x49048044D57e1C92A77f79988d21Fa8fAF74E97e",
l2OOAddress: "0x0000000000000000000000000000000000000000",
disputeGameFactory: "0x43edB88C4B80fDD2AdFF2412A7BebF9dF42cB40e",
anchorStateRegistry: "0x909f6cf47ed12f010A796527f562bFc26C7F4E72",
faultProofs: true,
},
"base-sepolia": {
l2RPC: "https://sepolia.base.org",
portalAddress: "0x49f53e41452C74589E85cA1677426Ba426459e85",
l2OOAddress: "0x0000000000000000000000000000000000000000",
disputeGameFactory: "0xd6E6dBf4F7EA0ac412fD8b65ED297e64BB7a06E1",
anchorStateRegistry: "0x2fF5cC82dBf333Ea30D8ee462178ab1707315355",
faultProofs: true,
},
"op-mainnet": {
l2RPC: "https://mainnet.optimism.io",
portalAddress: "0xbEb5Fc579115071764c7423A4f12eDde41f106Ed",
l2OOAddress: "0x0000000000000000000000000000000000000000",
disputeGameFactory: "0xe5965Ab5962eDc7477C8520243A95517CD252fA9",
anchorStateRegistry: "0x23B2C62946350F4246f9f9D027e071f0264FD113",
faultProofs: true,
},
"op-sepolia": {
l2RPC: "https://sepolia.optimism.io",
portalAddress: "0x16Fc5058F25648194471939df75CF27A2fdC48BC",
l2OOAddress: "0x0000000000000000000000000000000000000000",
disputeGameFactory: "0x05F9613aDB30026FFd634f38e5C4dFd30a197Fa1",
anchorStateRegistry: "0xa1Cec548926eb5d69aa3B7B57d371EdBdD03e64b",
faultProofs: true,
},
}
func main() {
var networkKeys []string
for n := range networks {
networkKeys = append(networkKeys, n)
}
var rpcFlag string
var networkFlag string
var l2RpcFlag string
var faultProofs bool
var portalAddress string
var l2OOAddress string
var dgfAddress string
var asrAddress string
var withdrawalFlag string
var privateKey string
var ledger bool
var mnemonic string
var hdPath string
var dryRun bool
var timeout time.Duration
var maxRetries int
var retryDelay time.Duration
// Gas configuration flags
var gasLimit uint64
var gasPrice string
var maxFeePerGas string
var maxPriorityFee string
var gasMultiplier float64
var maxGasPrice string
flag.StringVar(&rpcFlag, "rpc", "", "Ethereum L1 RPC url")
flag.StringVar(&networkFlag, "network", "base-mainnet", fmt.Sprintf("op-stack network to withdraw.go from (one of: %s)", strings.Join(networkKeys, ", ")))
flag.StringVar(&l2RpcFlag, "l2-rpc", "", "Custom network L2 RPC url")
flag.BoolVar(&faultProofs, "fault-proofs", false, "Use fault proofs")
flag.StringVar(&portalAddress, "portal-address", "", "Custom network OptimismPortal address")
flag.StringVar(&l2OOAddress, "l2oo-address", "", "Custom network L2OutputOracle address")
flag.StringVar(&dgfAddress, "dgf-address", "", "Custom network DisputeGameFactory address")
flag.StringVar(&asrAddress, "asr-address", "", "Custom network AnchorStateRegistry address")
flag.StringVar(&withdrawalFlag, "withdrawal", "", "TX hash of the L2 withdrawal transaction")
flag.StringVar(&privateKey, "private-key", "", "Private key to use for signing transactions")
flag.BoolVar(&ledger, "ledger", false, "Use ledger device for signing transactions")
flag.StringVar(&mnemonic, "mnemonic", "", "Mnemonic to use for signing transactions")
flag.StringVar(&hdPath, "hd-path", "m/44'/60'/0'/0/0", "Hierarchical deterministic derivation path for mnemonic or ledger")
// Gas configuration flags
flag.Uint64Var(&gasLimit, "gas-limit", 0, "Gas limit for transactions (overrides automatic estimation)")
flag.StringVar(&gasPrice, "gas-price", "", "Gas price in wei for legacy transactions")
flag.StringVar(&maxFeePerGas, "max-fee-per-gas", "", "Maximum fee per gas in wei for EIP-1559 transactions")
flag.StringVar(&maxPriorityFee, "max-priority-fee", "", "Maximum priority fee per gas in wei for EIP-1559 transactions")
flag.Float64Var(&gasMultiplier, "gas-multiplier", 1.0, "Multiplier for estimated gas limit (default 1.0)")
flag.StringVar(&maxGasPrice, "max-gas-price", "", "Maximum gas price cap in wei (safety limit)")
flag.BoolVar(&dryRun, "dry-run", false, "Simulate transactions and print details without submitting")
flag.DurationVar(&timeout, "timeout", 10*time.Minute, "Overall operation timeout (e.g. 30s, 10m, 1h)")
flag.IntVar(&maxRetries, "max-retries", withdraw.DefaultMaxRetries, "RPC retries after the initial call (0 disables retries)")
flag.DurationVar(&retryDelay, "retry-delay", withdraw.DefaultRetryDelay, "Initial RPC retry delay, doubled after each retry")
flag.Parse()
log.SetDefault(oplog.NewLogger(os.Stderr, oplog.DefaultCLIConfig()))
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
retryConfig := &withdraw.RetryConfig{MaxRetries: maxRetries, Delay: retryDelay}
if err := retryConfig.Validate(); err != nil {
log.Crit("Invalid RPC retry configuration", "error", err)
}
n, ok := networks[networkFlag]
if !ok {
log.Crit("Unknown network", "network", networkFlag)
}
// check for non-compatible networks with given flags
if faultProofs {
if n.faultProofs == false {
log.Crit("Fault proofs are not supported on this network")
}
} else {
if n.faultProofs == true {
log.Crit("Fault proofs are required on this network, please provide the --fault-proofs flag")
}
}
// check for non-empty flags for non-fault proof networks
if !faultProofs && (l2RpcFlag != "" || portalAddress != "" || l2OOAddress != "") {
if l2RpcFlag == "" {
log.Crit("Missing --l2-rpc flag")
}
if portalAddress == "" {
log.Crit("Missing --portal-address flag")
}
if l2OOAddress == "" {
log.Crit("Missing --l2oo-address flag")
}
n = network{
l2RPC: l2RpcFlag,
portalAddress: portalAddress,
l2OOAddress: l2OOAddress,
faultProofs: faultProofs,
}
}
// check for non-empty flags for fault proof networks
if faultProofs && (l2RpcFlag != "" || dgfAddress != "" || portalAddress != "" || asrAddress != "") {
if l2RpcFlag == "" {
log.Crit("Missing --l2-rpc flag")
}
if dgfAddress == "" {
log.Crit("Missing --dgf-address flag")
}
if portalAddress == "" {
log.Crit("Missing --portal-address flag")
}
if asrAddress == "" {
log.Crit("Missing --asr-address flag")
}
n = network{
l2RPC: l2RpcFlag,
portalAddress: portalAddress,
disputeGameFactory: dgfAddress,
anchorStateRegistry: asrAddress,
faultProofs: faultProofs,
}
}
if rpcFlag == "" {
log.Crit("Missing --rpc flag")
}
if withdrawalFlag == "" {
log.Crit("Missing --withdrawal flag")
}
withdrawal := common.HexToHash(withdrawalFlag)
options := 0
if privateKey != "" {
options++
}
if ledger {
options++
}
if mnemonic != "" {
options++
}
if options != 1 {
log.Crit("One (and only one) of --private-key, --ledger, --mnemonic must be set")
}
// Parse and validate gas configuration
gasConfig := GasConfig{
GasLimit: gasLimit,
GasMultiplier: gasMultiplier,
}
// Parse gas price (legacy transactions)
if gasPrice != "" {
gasPriceBig, ok := new(big.Int).SetString(gasPrice, 10)
if !ok {
log.Crit("Invalid --gas-price value", "value", gasPrice)
}
gasConfig.GasPrice = gasPriceBig
}
// Parse max fee per gas (EIP-1559)
if maxFeePerGas != "" {
maxFeeBig, ok := new(big.Int).SetString(maxFeePerGas, 10)
if !ok {
log.Crit("Invalid --max-fee-per-gas value", "value", maxFeePerGas)
}
gasConfig.MaxFeePerGas = maxFeeBig
}
// Parse max priority fee (EIP-1559)
if maxPriorityFee != "" {
maxPriorityBig, ok := new(big.Int).SetString(maxPriorityFee, 10)
if !ok {
log.Crit("Invalid --max-priority-fee value", "value", maxPriorityFee)
}
gasConfig.MaxPriorityFee = maxPriorityBig
}
// Parse max gas price (safety cap)
if maxGasPrice != "" {
maxGasPriceBig, ok := new(big.Int).SetString(maxGasPrice, 10)
if !ok {
log.Crit("Invalid --max-gas-price value", "value", maxGasPrice)
}
gasConfig.MaxGasPrice = maxGasPriceBig
}
// Validate gas configuration
if gasConfig.GasPrice != nil && (gasConfig.MaxFeePerGas != nil || gasConfig.MaxPriorityFee != nil) {
log.Crit("Cannot use --gas-price with EIP-1559 flags (--max-fee-per-gas, --max-priority-fee)")
}
// If one EIP-1559 flag is set, both should be set for clarity
if (gasConfig.MaxFeePerGas != nil) != (gasConfig.MaxPriorityFee != nil) {
log.Crit("Both --max-fee-per-gas and --max-priority-fee must be set for EIP-1559 transactions")
}
// Validate gas multiplier
if gasConfig.GasMultiplier < 1.0 {
log.Crit("--gas-multiplier must be >= 1.0", "value", gasConfig.GasMultiplier)
}
// Warn if gas multiplier is set but explicit gas limit is also provided
if gasConfig.GasMultiplier > 1.0 && gasConfig.GasLimit > 0 {
log.Warn("--gas-multiplier is ignored when --gas-limit is explicitly set", "gas-multiplier", gasConfig.GasMultiplier, "gas-limit", gasConfig.GasLimit)
}
// Validate max gas price cap against configured gas prices
if gasConfig.MaxGasPrice != nil {
if gasConfig.GasPrice != nil && gasConfig.GasPrice.Cmp(gasConfig.MaxGasPrice) > 0 {
log.Crit("--gas-price exceeds --max-gas-price safety cap", "gas-price", gasConfig.GasPrice, "max-gas-price", gasConfig.MaxGasPrice)
}
if gasConfig.MaxFeePerGas != nil && gasConfig.MaxFeePerGas.Cmp(gasConfig.MaxGasPrice) > 0 {
log.Crit("--max-fee-per-gas exceeds --max-gas-price safety cap", "max-fee-per-gas", gasConfig.MaxFeePerGas, "max-gas-price", gasConfig.MaxGasPrice)
}
}
// instantiate shared variables
s, err := signer.CreateSigner(privateKey, mnemonic, hdPath)
if err != nil {
log.Crit("Error creating signer", "error", err)
}
withdrawer, err := CreateWithdrawHelper(ctx, rpcFlag, withdrawal, n, s, gasConfig, dryRun, retryConfig)
if err != nil {
log.Crit("Error creating withdrawer", "error", err)
}
// handle withdrawals with or without the fault proofs withdrawer
isFinalized, err := withdrawer.IsProofFinalized()
if err != nil {
log.Crit("Error querying withdrawal finalization status", "error", err)
}
if isFinalized {
log.Info("Withdrawal already finalized")
return
}
// TODO: Add functionality to generate output root proposal and prove to that proposal for FPs
err = withdrawer.CheckIfProvable()
if err != nil {
log.Crit("Withdrawal is not provable", "error", err)
}
proofTime, err := withdrawer.GetProvenWithdrawalTime()
if err != nil {
log.Crit("Error querying withdrawal proof", "error", err)
}
if proofTime == 0 {
err = withdrawer.ProveWithdrawal()
if err != nil {
log.Crit("Error proving withdrawal", "error", err)
}
if faultProofs {
log.Info("Withdrawal successfully proven, finalize once dispute game finishes and finalization period elapses")
} else {
log.Info("Withdrawal successfully proven, finalize once finalization period elapses")
}
return
}
// TODO: Add edge-case handling for FPs if a withdrawal needs to be re-proven due to blacklisted / failed dispute game resolution
err = withdrawer.FinalizeWithdrawal()
if err != nil {
log.Crit("Error completing withdrawal", "error", err)
}
}
func CreateWithdrawHelper(ctx context.Context, l1Rpc string, withdrawal common.Hash, n network, s signer.Signer, gasConfig GasConfig, dryRun bool, configs ...*withdraw.RetryConfig) (withdraw.WithdrawHelper, error) {
var retryConfig *withdraw.RetryConfig
if len(configs) > 0 {
retryConfig = configs[0]
}
if retryConfig != nil {
if err := retryConfig.Validate(); err != nil {
return nil, err
}
}
l1Client, err := ethclient.DialContext(ctx, l1Rpc)
if err != nil {
return nil, fmt.Errorf("Error dialing L1 client: %w", err)
}
backend := &operationBackend{contractBackend: withdraw.NewRetryingBackend(ctx, l1Client, retryConfig), ctx: ctx}
var l1ChainID *big.Int
err = retryConfig.Do(ctx, "eth_chainId", func() error {
var err error
l1ChainID, err = l1Client.ChainID(ctx)
return err
})
if err != nil {
return nil, fmt.Errorf("Error querying chain ID: %w", err)
}
l1opts := &bind.TransactOpts{
From: s.Address(),
Signer: s.SignerFn(l1ChainID),
Context: ctx,
}
// Apply gas configuration to TransactOpts
if gasConfig.GasLimit > 0 {
l1opts.GasLimit = gasConfig.GasLimit
log.Info("Using custom gas limit", "gas-limit", gasConfig.GasLimit)
}
// Log gas multiplier if set (actual application happens in withdraw functions)
if gasConfig.GasMultiplier > 1.0 && gasConfig.GasLimit == 0 {
log.Info("Using gas multiplier", "multiplier", gasConfig.GasMultiplier)
}
// Apply legacy gas price or EIP-1559 pricing
if gasConfig.GasPrice != nil {
l1opts.GasPrice = gasConfig.GasPrice
log.Info("Using legacy gas price", "gas-price", gasConfig.GasPrice.String())
} else if gasConfig.MaxFeePerGas != nil && gasConfig.MaxPriorityFee != nil {
l1opts.GasFeeCap = gasConfig.MaxFeePerGas
l1opts.GasTipCap = gasConfig.MaxPriorityFee
log.Info("Using EIP-1559 gas pricing", "max-fee-per-gas", gasConfig.MaxFeePerGas.String(), "max-priority-fee", gasConfig.MaxPriorityFee.String())
} else {
// No gas price specified - will use RPC defaults
// Log estimated gas prices for visibility
suggestedGasPrice, err := backend.SuggestGasPrice(ctx)
if err != nil {
log.Warn("Failed to get suggested gas price", "error", err)
} else {
log.Info("Using RPC suggested gas price", "suggested-gas-price", suggestedGasPrice.String())
// Apply max gas price safety cap if configured
if gasConfig.MaxGasPrice != nil && suggestedGasPrice.Cmp(gasConfig.MaxGasPrice) > 0 {
return nil, fmt.Errorf("suggested gas price %s exceeds max gas price cap %s", suggestedGasPrice.String(), gasConfig.MaxGasPrice.String())
}
}
// Also check EIP-1559 suggested tip cap for networks that support it
suggestedTipCap, err := backend.SuggestGasTipCap(ctx)
if err != nil {
// Not all networks support EIP-1559, so just log a debug message
log.Debug("Failed to get suggested gas tip cap (network may not support EIP-1559)", "error", err)
} else {
log.Info("RPC suggested gas tip cap", "suggested-tip-cap", suggestedTipCap.String())
// Apply max gas price safety cap to tip cap if configured
if gasConfig.MaxGasPrice != nil && suggestedTipCap.Cmp(gasConfig.MaxGasPrice) > 0 {
return nil, fmt.Errorf("suggested gas tip cap %s exceeds max gas price cap %s", suggestedTipCap.String(), gasConfig.MaxGasPrice.String())
}
}
}
// Log max gas price safety cap if configured
if gasConfig.MaxGasPrice != nil {
log.Info("Max gas price safety cap enabled", "max-gas-price", gasConfig.MaxGasPrice.String())
}
l2Client, err := rpc.DialContext(ctx, n.l2RPC)
if err != nil {
return nil, fmt.Errorf("Error dialing L2 client: %w", err)
}
if n.faultProofs {
portal, err := bindingspreview.NewOptimismPortal2(common.HexToAddress(n.portalAddress), backend)
if err != nil {
return nil, fmt.Errorf("Error binding OptimismPortal2 contract: %w", err)
}
dgf, err := bindings.NewDisputeGameFactory(common.HexToAddress(n.disputeGameFactory), backend)
if err != nil {
return nil, fmt.Errorf("Error binding DisputeGameFactory contract: %w", err)
}
anchorStateRegistry, err := withdrawerbindings.NewAnchorStateRegistry(common.HexToAddress(n.anchorStateRegistry), backend)
if err != nil {
return nil, fmt.Errorf("Error binding AnchorStateRegistry contract: %w", err)
}
return &withdraw.FPWithdrawer{
Ctx: ctx,
L1Client: l1Client,
L2Client: l2Client,
L2TxHash: withdrawal,
Portal: portal,
Factory: dgf,
AnchorStateRegistry: anchorStateRegistry,
Opts: l1opts,
GasMultiplier: gasConfig.GasMultiplier,
UserGasLimit: gasConfig.GasLimit,
DryRun: dryRun,
Retry: retryConfig,
}, nil
} else {
portal, err := bindings.NewOptimismPortal(common.HexToAddress(n.portalAddress), backend)
if err != nil {
return nil, fmt.Errorf("Error binding OptimismPortal contract: %w", err)
}
l2oo, err := bindings.NewL2OutputOracle(common.HexToAddress(n.l2OOAddress), backend)
if err != nil {
return nil, fmt.Errorf("Error binding L2OutputOracle contract: %w", err)
}
return &withdraw.Withdrawer{
Ctx: ctx,
L1Client: l1Client,
L2Client: l2Client,
L2TxHash: withdrawal,
Portal: portal,
Oracle: l2oo,
Opts: l1opts,
GasMultiplier: gasConfig.GasMultiplier,
UserGasLimit: gasConfig.GasLimit,
DryRun: dryRun,
Retry: retryConfig,
}, nil
}
}
type contractBackend interface {
bind.ContractBackend
bind.PendingContractCaller
bind.BlockHashContractCaller
}
// Optimism v1.13.5 withdrawal helpers omit CallOpts.Context on some L1 calls.
type operationBackend struct {
contractBackend
ctx context.Context
}
type operationCancellation struct {
error
}
func (e operationCancellation) Unwrap() error { return e.error }
func (b *operationBackend) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) {
ctx, cancel := b.callContext(ctx)
defer cancel()
result, err := b.contractBackend.CallContract(ctx, msg, blockNumber)
if errors.Is(err, context.Canceled) {
if cause := context.Cause(ctx); cause != nil {
err = cause
} else if b.ctx.Err() != nil {
err = b.ctx.Err()
}
}
return result, err
}
func (b *operationBackend) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error) {
ctx, cancel := b.callContext(ctx)
defer cancel()
result, err := b.contractBackend.CodeAt(ctx, account, blockNumber)
if errors.Is(err, context.Canceled) {
if cause := context.Cause(ctx); cause != nil {
err = cause
} else if b.ctx.Err() != nil {
err = b.ctx.Err()
}
}
return result, err
}
func (b *operationBackend) callContext(ctx context.Context) (context.Context, context.CancelFunc) {
ctx, cancel := context.WithCancelCause(ctx)
cancelDeadline := func() {}
if deadline, ok := b.ctx.Deadline(); ok {
ctx, cancelDeadline = context.WithDeadline(ctx, deadline)
}
stop := context.AfterFunc(b.ctx, func() { cancel(operationCancellation{b.ctx.Err()}) })
if err := b.ctx.Err(); err != nil {
cancel(operationCancellation{err})
}
return ctx, func() {
stop()
cancelDeadline()
cancel(nil)
}
}