forked from erigontech/erigon
-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathdebug_api.go
More file actions
629 lines (566 loc) · 20.2 KB
/
debug_api.go
File metadata and controls
629 lines (566 loc) · 20.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
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
// Copyright 2024 The Erigon Authors
// This file is part of Erigon.
//
// Erigon is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Erigon is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Erigon. If not, see <http://www.gnu.org/licenses/>.
package jsonrpc
import (
"bytes"
"context"
"errors"
"fmt"
"github.com/erigontech/erigon/execution/consensus"
"github.com/erigontech/erigon/execution/stagedsync"
"runtime"
"runtime/debug"
"github.com/erigontech/erigon-lib/common"
"github.com/erigontech/erigon-lib/common/hexutil"
"github.com/erigontech/erigon-lib/log/v3"
"github.com/erigontech/erigon/core/state"
"github.com/erigontech/erigon/db/kv"
"github.com/erigontech/erigon/db/kv/order"
"github.com/erigontech/erigon/db/rawdb"
tracersConfig "github.com/erigontech/erigon/eth/tracers/config"
"github.com/erigontech/erigon/execution/rlp"
"github.com/erigontech/erigon/execution/stagedsync/stages"
"github.com/erigontech/erigon/execution/types/accounts"
"github.com/erigontech/erigon/rpc"
"github.com/erigontech/erigon/rpc/ethapi"
"github.com/erigontech/erigon/rpc/jsonstream"
"github.com/erigontech/erigon/rpc/rpchelper"
)
// AccountRangeMaxResults is the maximum number of results to be returned
const AccountRangeMaxResults = 8192
// AccountRangeMaxResultsWithStorage is the maximum number of results to be returned
// if storage is asked to be enclosed. Contract storage is usually huge and we should
// be careful not overwhelming our clients or being stuck in db.
const AccountRangeMaxResultsWithStorage = 256
// PrivateDebugAPI Exposed RPC endpoints for debugging use
type PrivateDebugAPI interface {
StorageRangeAt(ctx context.Context, blockHash common.Hash, txIndex uint64, contractAddress common.Address, keyStart hexutil.Bytes, maxResult int) (StorageRangeResult, error)
TraceTransaction(ctx context.Context, hash common.Hash, config *tracersConfig.TraceConfig, stream jsonstream.Stream) error
TraceBlockByHash(ctx context.Context, hash common.Hash, config *tracersConfig.TraceConfig, stream jsonstream.Stream) error
TraceBlockByNumber(ctx context.Context, number rpc.BlockNumber, config *tracersConfig.TraceConfig, stream jsonstream.Stream) error
AccountRange(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash, start []byte, maxResults int, nocode, nostorage bool) (state.IteratorDump, error)
GetModifiedAccountsByNumber(ctx context.Context, startNum rpc.BlockNumber, endNum *rpc.BlockNumber) ([]common.Address, error)
GetModifiedAccountsByHash(ctx context.Context, startHash common.Hash, endHash *common.Hash) ([]common.Address, error)
TraceCall(ctx context.Context, args ethapi.CallArgs, blockNrOrHash rpc.BlockNumberOrHash, config *tracersConfig.TraceConfig, stream jsonstream.Stream) error
AccountAt(ctx context.Context, blockHash common.Hash, txIndex uint64, account common.Address) (*AccountResult, error)
GetRawHeader(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (hexutil.Bytes, error)
GetRawBlock(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (hexutil.Bytes, error)
GetRawReceipts(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]hexutil.Bytes, error)
GetBadBlocks(ctx context.Context) ([]map[string]interface{}, error)
GetRawTransaction(ctx context.Context, hash common.Hash) (hexutil.Bytes, error)
FreeOSMemory()
SetGCPercent(v int) int
SetMemoryLimit(limit int64) int64
GcStats() *debug.GCStats
MemStats() *runtime.MemStats
}
// PrivateDebugAPIImpl is implementation of the PrivateDebugAPI interface based on remote Db access
type DebugAPIImpl struct {
*BaseAPI
db kv.TemporalRoDB
GasCap uint64
}
// NewPrivateDebugAPI returns PrivateDebugAPIImpl instance
func NewPrivateDebugAPI(base *BaseAPI, db kv.TemporalRoDB, gascap uint64) *DebugAPIImpl {
return &DebugAPIImpl{
BaseAPI: base,
db: db,
GasCap: gascap,
}
}
// storageRangeAt implements debug_storageRangeAt. Returns information about a range of storage locations (if any) for the given address.
func (api *DebugAPIImpl) StorageRangeAt(ctx context.Context, blockHash common.Hash, txIndex uint64, contractAddress common.Address, keyStart hexutil.Bytes, maxResult int) (StorageRangeResult, error) {
tx, err := api.db.BeginTemporalRo(ctx)
if err != nil {
return StorageRangeResult{}, err
}
defer tx.Rollback()
number, err := api._blockReader.HeaderNumber(ctx, tx, blockHash)
if err != nil {
return StorageRangeResult{}, err
}
if number == nil {
return StorageRangeResult{}, nil
}
minTxNum, err := api._txNumReader.Min(tx, *number)
if err != nil {
return StorageRangeResult{}, err
}
fromTxNum := minTxNum + txIndex + 1 //+1 for system txn in the beginning of block
return storageRangeAt(tx, contractAddress, keyStart, fromTxNum, maxResult)
}
// AccountRange implements debug_accountRange. Returns a range of accounts involved in the given block rangeb
func (api *DebugAPIImpl) AccountRange(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash, startKey []byte, maxResults int, excludeCode, excludeStorage bool) (state.IteratorDump, error) {
tx, err := api.db.BeginTemporalRo(ctx)
if err != nil {
return state.IteratorDump{}, err
}
defer tx.Rollback()
var blockNumber uint64
if number, ok := blockNrOrHash.Number(); ok {
if number == rpc.PendingBlockNumber {
return state.IteratorDump{}, errors.New("accountRange for pending block not supported")
}
if number == rpc.LatestBlockNumber {
var err error
blockNumber, err = stages.GetStageProgress(tx, stages.Execution)
if err != nil {
return state.IteratorDump{}, fmt.Errorf("last block has not found: %w", err)
}
} else if number == rpc.FinalizedBlockNumber {
if posa, isPoSA := api.engine().(consensus.PoSA); isPoSA {
headerNumber, err := stages.GetStageProgress(tx, stages.Execution)
if err != nil {
return state.IteratorDump{}, err
}
header, err := api._blockReader.HeaderByNumber(ctx, tx, headerNumber)
if err != nil {
return state.IteratorDump{}, err
}
if header == nil {
return state.IteratorDump{}, nil
}
canonicalHash, _, _ := api._blockReader.CanonicalHash(ctx, tx, headerNumber)
isCanonical := canonicalHash == header.Hash()
if !isCanonical {
return state.IteratorDump{}, errors.New("block hash is not canonical")
}
if chainConfig, err := api.chainConfig(ctx, tx); err == nil {
blockNumber = posa.GetFinalizedHeader(stagedsync.NewChainReaderImpl(chainConfig, tx, nil, nil), header).Number.Uint64()
}
}
} else if number == rpc.SafeBlockNumber {
if posa, isPoSA := api.engine().(consensus.PoSA); isPoSA {
headerNumber, err := stages.GetStageProgress(tx, stages.Execution)
if err != nil {
return state.IteratorDump{}, err
}
header, err := api._blockReader.HeaderByNumber(ctx, tx, headerNumber)
if err != nil {
return state.IteratorDump{}, err
}
if header == nil {
return state.IteratorDump{}, nil
}
canonicalHash, _, _ := api._blockReader.CanonicalHash(ctx, tx, headerNumber)
isCanonical := canonicalHash == header.Hash()
if !isCanonical {
return state.IteratorDump{}, errors.New("block hash is not canonical")
}
if chainConfig, err := api.chainConfig(ctx, tx); err == nil {
blockNumber, _, err = posa.GetJustifiedNumberAndHash(stagedsync.NewChainReaderImpl(chainConfig, tx, nil, nil), header)
if err != nil {
return state.IteratorDump{}, err
}
}
}
} else {
blockNumber = uint64(number)
}
} else if hash, ok := blockNrOrHash.Hash(); ok {
header, err1 := api.headerByHash(ctx, hash, tx)
if err1 != nil {
return state.IteratorDump{}, err1
}
if header == nil {
return state.IteratorDump{}, fmt.Errorf("header %s not found", hash.Hex())
}
blockNumber = header.Number.Uint64()
}
// Determine how many results we will dump
if excludeStorage {
// Plain addresses
if maxResults > AccountRangeMaxResults || maxResults <= 0 {
maxResults = AccountRangeMaxResults
}
} else {
// With storage
if maxResults > AccountRangeMaxResultsWithStorage || maxResults <= 0 {
maxResults = AccountRangeMaxResultsWithStorage
}
}
dumper := state.NewDumper(tx, api._blockReader.TxnumReader(ctx), blockNumber)
res, err := dumper.IteratorDump(excludeCode, excludeStorage, common.BytesToAddress(startKey), maxResults)
if err != nil {
return state.IteratorDump{}, err
}
header, err := api._blockReader.HeaderByNumber(ctx, tx, blockNumber)
if err != nil {
return state.IteratorDump{}, err
}
if header != nil {
res.Root = header.Root.String()
}
return res, nil
}
// GetModifiedAccountsByNumber implements debug_getModifiedAccountsByNumber. Returns a list of accounts modified in the given block.
// [from, to)
func (api *DebugAPIImpl) GetModifiedAccountsByNumber(ctx context.Context, startNumber rpc.BlockNumber, endNumber *rpc.BlockNumber) ([]common.Address, error) {
tx, err := api.db.BeginTemporalRo(ctx)
if err != nil {
return nil, err
}
defer tx.Rollback()
latestBlock, err := stages.GetStageProgress(tx, stages.Execution)
if err != nil {
return nil, err
}
// forces negative numbers to fail (too large) but allows zero
startNum := uint64(startNumber.Int64())
if startNum > latestBlock {
return nil, fmt.Errorf("start block (%d) is later than the latest block (%d)", startNum, latestBlock)
}
endNum := startNum + 1 // allows for single param calls
if endNumber != nil {
// forces negative numbers to fail (too large) but allows zero
endNum = uint64(endNumber.Int64()) + 1
}
// is endNum too big?
if endNum > latestBlock {
return nil, fmt.Errorf("end block (%d) is later than the latest block (%d)", endNum, latestBlock)
}
if startNum > endNum {
return nil, fmt.Errorf("start block (%d) must be less than or equal to end block (%d)", startNum, endNum)
}
//[from, to)
startTxNum, err := api._txNumReader.Min(tx, startNum)
if err != nil {
return nil, err
}
endTxNum, err := api._txNumReader.Min(tx, endNum)
if err != nil {
return nil, err
}
return getModifiedAccounts(tx, startTxNum, endTxNum-1)
}
// getModifiedAccounts returns a list of addresses that were modified in the block range
// [startNum:endNum)
func getModifiedAccounts(tx kv.TemporalTx, startTxNum, endTxNum uint64) ([]common.Address, error) {
it, err := tx.HistoryRange(kv.AccountsDomain, int(startTxNum), int(endTxNum), order.Asc, kv.Unlim)
if err != nil {
return nil, err
}
defer it.Close()
var result []common.Address
saw := make(map[common.Address]struct{})
for it.HasNext() {
k, _, err := it.Next()
if err != nil {
return nil, err
}
//TODO: data is sorted, enough to compare with prevKey
if _, ok := saw[common.BytesToAddress(k)]; !ok {
saw[common.BytesToAddress(k)] = struct{}{}
result = append(result, common.BytesToAddress(k))
}
}
return result, nil
}
// GetModifiedAccountsByHash implements debug_getModifiedAccountsByHash. Returns a list of accounts modified in the given block.
func (api *DebugAPIImpl) GetModifiedAccountsByHash(ctx context.Context, startHash common.Hash, endHash *common.Hash) ([]common.Address, error) {
tx, err := api.db.BeginTemporalRo(ctx)
if err != nil {
return nil, err
}
defer tx.Rollback()
startNum, err := api.headerNumberByHash(ctx, tx, startHash)
if err != nil {
return nil, fmt.Errorf("start block %x not found", startHash)
}
endNum := startNum + 1 // allows for single parameter calls
if endHash != nil {
var err error
endNum, err = api.headerNumberByHash(ctx, tx, *endHash)
if err != nil {
return nil, fmt.Errorf("end block %x not found", *endHash)
}
endNum = endNum + 1
}
if startNum > endNum {
return nil, fmt.Errorf("start block (%d) must be less than or equal to end block (%d)", startNum, endNum)
}
//[from, to)
startTxNum, err := api._txNumReader.Min(tx, startNum)
if err != nil {
return nil, err
}
endTxNum, err := api._txNumReader.Min(tx, endNum)
if err != nil {
return nil, err
}
return getModifiedAccounts(tx, startTxNum, endTxNum-1)
}
func (api *DebugAPIImpl) AccountAt(ctx context.Context, blockHash common.Hash, txIndex uint64, address common.Address) (*AccountResult, error) {
tx, err := api.db.BeginTemporalRo(ctx)
if err != nil {
return nil, err
}
defer tx.Rollback()
header, err := api.headerByHash(ctx, blockHash, tx)
if err != nil {
return &AccountResult{}, err
}
if header == nil || header.Number == nil {
return nil, nil // not error, see https://github.com/erigontech/erigon/issues/1645
}
canonicalHash, ok, err := api._blockReader.CanonicalHash(ctx, tx, header.Number.Uint64())
if err != nil {
return nil, err
}
if !ok {
return nil, fmt.Errorf("canonical hash not found %d", header.Number.Uint64())
}
isCanonical := canonicalHash == blockHash
if !isCanonical {
return nil, errors.New("block hash is not canonical")
}
minTxNum, err := api._txNumReader.Min(tx, header.Number.Uint64())
if err != nil {
return nil, err
}
ttx := tx
v, ok, err := ttx.GetAsOf(kv.AccountsDomain, address[:], minTxNum+txIndex+1)
if err != nil {
return nil, err
}
if !ok || len(v) == 0 {
return &AccountResult{}, nil
}
var a accounts.Account
if err := accounts.DeserialiseV3(&a, v); err != nil {
return nil, err
}
result := &AccountResult{}
result.Balance.ToInt().Set(a.Balance.ToBig())
result.Nonce = hexutil.Uint64(a.Nonce)
result.CodeHash = a.CodeHash
code, _, err := ttx.GetAsOf(kv.CodeDomain, address[:], minTxNum+txIndex)
if err != nil {
return nil, err
}
result.Code = code
return result, nil
}
type AccountResult struct {
Balance hexutil.Big `json:"balance"`
Nonce hexutil.Uint64 `json:"nonce"`
Code hexutil.Bytes `json:"code"`
CodeHash common.Hash `json:"codeHash"`
}
// GetRawHeader implements debug_getRawHeader - returns a an RLP-encoded header, given a block number or hash
func (api *DebugAPIImpl) GetRawHeader(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (hexutil.Bytes, error) {
tx, err := api.db.BeginTemporalRo(ctx)
if err != nil {
return nil, err
}
defer tx.Rollback()
n, h, _, err := rpchelper.GetBlockNumber(ctx, blockNrOrHash, tx, api._blockReader, api.filters)
if err != nil {
return nil, err
}
header, err := api._blockReader.Header(ctx, tx, h, n)
if err != nil {
return nil, err
}
if header == nil {
return nil, nil
}
return rlp.EncodeToBytes(header)
}
// Implements debug_getRawBlock - Returns an RLP-encoded block
func (api *DebugAPIImpl) GetRawBlock(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (hexutil.Bytes, error) {
tx, err := api.db.BeginTemporalRo(ctx)
if err != nil {
return nil, err
}
defer tx.Rollback()
n, h, _, err := rpchelper.GetBlockNumber(ctx, blockNrOrHash, tx, api._blockReader, api.filters)
if err != nil {
return nil, err
}
block, err := api.blockWithSenders(ctx, tx, h, n)
if err != nil {
return nil, err
}
if block == nil {
return nil, nil
}
return rlp.EncodeToBytes(block)
}
// GetRawReceipts implements debug_getRawReceipts - retrieves and returns an array of EIP-2718 binary-encoded receipts of a single block
func (api *DebugAPIImpl) GetRawReceipts(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]hexutil.Bytes, error) {
tx, err := api.db.BeginTemporalRo(ctx)
if err != nil {
return nil, err
}
defer tx.Rollback()
blockNum, blockHash, _, err := rpchelper.GetBlockNumber(ctx, blockNrOrHash, tx, api._blockReader, api.filters)
if err != nil {
return nil, err
}
block, err := api.blockWithSenders(ctx, tx, blockHash, blockNum)
if err != nil {
return nil, err
}
if block == nil {
return nil, nil
}
receipts, err := api.getReceipts(ctx, tx, block)
if err != nil {
return nil, fmt.Errorf("getReceipts error: %w", err)
}
chainConfig, err := api.chainConfig(ctx, tx)
if err != nil {
return nil, err
}
if chainConfig.Bor != nil {
events, err := api.bridgeReader.Events(ctx, block.Hash(), blockNum)
if err != nil {
return nil, err
}
if len(events) != 0 {
borReceipt, err := api.borReceiptGenerator.GenerateBorReceipt(ctx, tx, block, events, chainConfig)
if err != nil {
return nil, err
}
receipts = append(receipts, borReceipt)
}
}
result := make([]hexutil.Bytes, len(receipts))
for i, receipt := range receipts {
b, err := receipt.MarshalBinary()
if err != nil {
return nil, err
}
result[i] = b
}
return result, nil
}
// GetBadBlocks implements debug_getBadBlocks - Returns an array of recent bad blocks that the client has seen on the network
func (api *DebugAPIImpl) GetBadBlocks(ctx context.Context) ([]map[string]interface{}, error) {
tx, err := api.db.BeginTemporalRo(ctx)
if err != nil {
return nil, err
}
defer tx.Rollback()
blocks, err := rawdb.GetLatestBadBlocks(tx)
if err != nil || len(blocks) == 0 {
return nil, err
}
results := make([]map[string]interface{}, 0, len(blocks))
for _, block := range blocks {
var blockRlp string
if rlpBytes, err := rlp.EncodeToBytes(block); err != nil {
blockRlp = err.Error() // hack
} else {
blockRlp = fmt.Sprintf("%#x", rlpBytes)
}
blockJson, err := ethapi.RPCMarshalBlock(block, true, true, nil)
if err != nil {
log.Error("Failed to marshal block", "err", err)
blockJson = map[string]interface{}{}
}
results = append(results, map[string]interface{}{
"hash": block.Hash(),
"block": blockRlp,
"rlp": blockJson,
})
}
return results, nil
}
// GetRawTransaction implements debug_getRawTransaction - Returns an array of EIP-2718 binary-encoded transactions
func (api *DebugAPIImpl) GetRawTransaction(ctx context.Context, txnHash common.Hash) (hexutil.Bytes, error) {
tx, err := api.db.BeginTemporalRo(ctx)
if err != nil {
return nil, err
}
defer tx.Rollback()
chainConfig, err := api.chainConfig(ctx, tx)
if err != nil {
return nil, err
}
blockNum, txNum, ok, err := api.txnLookup(ctx, tx, txnHash)
if err != nil {
return nil, err
}
// Private API returns 0 if transaction is not found.
isBorStateSyncTx := blockNum == 0 && chainConfig.Bor != nil
if isBorStateSyncTx {
blockNum, ok, err = api.bridgeReader.EventTxnLookup(ctx, txnHash)
if err != nil {
return nil, err
}
}
if !ok {
return nil, nil
}
txNumMin, err := api._txNumReader.Min(tx, blockNum)
if err != nil {
return nil, err
}
if txNumMin+1 > txNum && !isBorStateSyncTx {
return nil, fmt.Errorf("uint underflow txnums error txNum: %d, txNumMin: %d, blockNum: %d", txNum, txNumMin, blockNum)
}
var txnIndex = txNum - txNumMin - 1
txn, err := api._txnReader.TxnByIdxInBlock(ctx, tx, blockNum, int(txnIndex))
if err != nil {
return nil, err
}
if txn != nil {
var buf bytes.Buffer
err = txn.MarshalBinary(&buf)
return buf.Bytes(), err
}
return nil, nil
}
// MemStats returns detailed runtime memory statistics.
func (api *DebugAPIImpl) MemStats() *runtime.MemStats {
s := new(runtime.MemStats)
runtime.ReadMemStats(s)
return s
}
// GcStats returns GC statistics.
func (api *DebugAPIImpl) GcStats() *debug.GCStats {
s := new(debug.GCStats)
debug.ReadGCStats(s)
return s
}
// FreeOSMemory forces a garbage collection.
func (api *DebugAPIImpl) FreeOSMemory() {
debug.FreeOSMemory()
}
// SetGCPercent sets the garbage collection target percentage. It returns the previous
// setting. A negative value disables GC.
func (api *DebugAPIImpl) SetGCPercent(v int) int {
return debug.SetGCPercent(v)
}
// SetMemoryLimit sets the GOMEMLIMIT for the process. It returns the previous limit.
// Note:
//
// - The input limit is provided as bytes. A negative input does not adjust the limit
//
// - A zero limit or a limit that's lower than the amount of memory used by the Go
// runtime may cause the garbage collector to run nearly continuously. However,
// the application may still make progress.
//
// - Setting the limit too low will cause Geth to become unresponsive.
//
// - Geth also allocates memory off-heap, particularly for fastCache and Pebble,
// which can be non-trivial (a few gigabytes by default).
func (api *DebugAPIImpl) SetMemoryLimit(limit int64) int64 {
log.Info("Setting memory limit", "size", common.PrettyDuration(limit))
return debug.SetMemoryLimit(limit)
}