api.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. // Copyright 2015 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package eth
  17. import (
  18. "compress/gzip"
  19. "context"
  20. "errors"
  21. "fmt"
  22. "io"
  23. "math/big"
  24. "os"
  25. "runtime"
  26. "strings"
  27. "time"
  28. "github.com/ethereum/go-ethereum/common"
  29. "github.com/ethereum/go-ethereum/common/hexutil"
  30. "github.com/ethereum/go-ethereum/core"
  31. "github.com/ethereum/go-ethereum/core/rawdb"
  32. "github.com/ethereum/go-ethereum/core/state"
  33. "github.com/ethereum/go-ethereum/core/types"
  34. "github.com/ethereum/go-ethereum/internal/ethapi"
  35. "github.com/ethereum/go-ethereum/log"
  36. "github.com/ethereum/go-ethereum/rlp"
  37. "github.com/ethereum/go-ethereum/rpc"
  38. "github.com/ethereum/go-ethereum/trie"
  39. )
  40. // EthereumAPI provides an API to access Ethereum full node-related information.
  41. type EthereumAPI struct {
  42. e *Ethereum
  43. }
  44. // NewEthereumAPI creates a new Ethereum protocol API for full nodes.
  45. func NewEthereumAPI(e *Ethereum) *EthereumAPI {
  46. return &EthereumAPI{e}
  47. }
  48. // Etherbase is the address that mining rewards will be send to.
  49. func (api *EthereumAPI) Etherbase() (common.Address, error) {
  50. return api.e.Etherbase()
  51. }
  52. // Coinbase is the address that mining rewards will be send to (alias for Etherbase).
  53. func (api *EthereumAPI) Coinbase() (common.Address, error) {
  54. return api.Etherbase()
  55. }
  56. // Hashrate returns the POW hashrate.
  57. func (api *EthereumAPI) Hashrate() hexutil.Uint64 {
  58. return hexutil.Uint64(api.e.Miner().Hashrate())
  59. }
  60. // Mining returns an indication if this node is currently mining.
  61. func (api *EthereumAPI) Mining() bool {
  62. return api.e.IsMining()
  63. }
  64. // MinerAPI provides an API to control the miner.
  65. type MinerAPI struct {
  66. e *Ethereum
  67. }
  68. // NewMinerAPI create a new MinerAPI instance.
  69. func NewMinerAPI(e *Ethereum) *MinerAPI {
  70. return &MinerAPI{e}
  71. }
  72. // Start starts the miner with the given number of threads. If threads is nil,
  73. // the number of workers started is equal to the number of logical CPUs that are
  74. // usable by this process. If mining is already running, this method adjust the
  75. // number of threads allowed to use and updates the minimum price required by the
  76. // transaction pool.
  77. func (api *MinerAPI) Start(threads *int) error {
  78. if threads == nil {
  79. return api.e.StartMining(runtime.NumCPU())
  80. }
  81. return api.e.StartMining(*threads)
  82. }
  83. // Stop terminates the miner, both at the consensus engine level as well as at
  84. // the block creation level.
  85. func (api *MinerAPI) Stop() {
  86. api.e.StopMining()
  87. }
  88. // SetExtra sets the extra data string that is included when this miner mines a block.
  89. func (api *MinerAPI) SetExtra(extra string) (bool, error) {
  90. if err := api.e.Miner().SetExtra([]byte(extra)); err != nil {
  91. return false, err
  92. }
  93. return true, nil
  94. }
  95. // SetGasPrice sets the minimum accepted gas price for the miner.
  96. func (api *MinerAPI) SetGasPrice(gasPrice hexutil.Big) bool {
  97. api.e.lock.Lock()
  98. api.e.gasPrice = (*big.Int)(&gasPrice)
  99. api.e.lock.Unlock()
  100. api.e.txPool.SetGasPrice((*big.Int)(&gasPrice))
  101. return true
  102. }
  103. // SetGasLimit sets the gaslimit to target towards during mining.
  104. func (api *MinerAPI) SetGasLimit(gasLimit hexutil.Uint64) bool {
  105. api.e.Miner().SetGasCeil(uint64(gasLimit))
  106. return true
  107. }
  108. // SetEtherbase sets the etherbase of the miner.
  109. func (api *MinerAPI) SetEtherbase(etherbase common.Address) bool {
  110. api.e.SetEtherbase(etherbase)
  111. return true
  112. }
  113. // SetRecommitInterval updates the interval for miner sealing work recommitting.
  114. func (api *MinerAPI) SetRecommitInterval(interval int) {
  115. api.e.Miner().SetRecommitInterval(time.Duration(interval) * time.Millisecond)
  116. }
  117. // AdminAPI is the collection of Ethereum full node related APIs for node
  118. // administration.
  119. type AdminAPI struct {
  120. eth *Ethereum
  121. }
  122. // NewAdminAPI creates a new instance of AdminAPI.
  123. func NewAdminAPI(eth *Ethereum) *AdminAPI {
  124. return &AdminAPI{eth: eth}
  125. }
  126. // ExportChain exports the current blockchain into a local file,
  127. // or a range of blocks if first and last are non-nil.
  128. func (api *AdminAPI) ExportChain(file string, first *uint64, last *uint64) (bool, error) {
  129. if first == nil && last != nil {
  130. return false, errors.New("last cannot be specified without first")
  131. }
  132. if first != nil && last == nil {
  133. head := api.eth.BlockChain().CurrentHeader().Number.Uint64()
  134. last = &head
  135. }
  136. if _, err := os.Stat(file); err == nil {
  137. // File already exists. Allowing overwrite could be a DoS vector,
  138. // since the 'file' may point to arbitrary paths on the drive.
  139. return false, errors.New("location would overwrite an existing file")
  140. }
  141. // Make sure we can create the file to export into
  142. out, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.ModePerm)
  143. if err != nil {
  144. return false, err
  145. }
  146. defer out.Close()
  147. var writer io.Writer = out
  148. if strings.HasSuffix(file, ".gz") {
  149. writer = gzip.NewWriter(writer)
  150. defer writer.(*gzip.Writer).Close()
  151. }
  152. // Export the blockchain
  153. if first != nil {
  154. if err := api.eth.BlockChain().ExportN(writer, *first, *last); err != nil {
  155. return false, err
  156. }
  157. } else if err := api.eth.BlockChain().Export(writer); err != nil {
  158. return false, err
  159. }
  160. return true, nil
  161. }
  162. func hasAllBlocks(chain *core.BlockChain, bs []*types.Block) bool {
  163. for _, b := range bs {
  164. if !chain.HasBlock(b.Hash(), b.NumberU64()) {
  165. return false
  166. }
  167. }
  168. return true
  169. }
  170. // ImportChain imports a blockchain from a local file.
  171. func (api *AdminAPI) ImportChain(file string) (bool, error) {
  172. // Make sure the can access the file to import
  173. in, err := os.Open(file)
  174. if err != nil {
  175. return false, err
  176. }
  177. defer in.Close()
  178. var reader io.Reader = in
  179. if strings.HasSuffix(file, ".gz") {
  180. if reader, err = gzip.NewReader(reader); err != nil {
  181. return false, err
  182. }
  183. }
  184. // Run actual the import in pre-configured batches
  185. stream := rlp.NewStream(reader, 0)
  186. blocks, index := make([]*types.Block, 0, 2500), 0
  187. for batch := 0; ; batch++ {
  188. // Load a batch of blocks from the input file
  189. for len(blocks) < cap(blocks) {
  190. block := new(types.Block)
  191. if err := stream.Decode(block); err == io.EOF {
  192. break
  193. } else if err != nil {
  194. return false, fmt.Errorf("block %d: failed to parse: %v", index, err)
  195. }
  196. blocks = append(blocks, block)
  197. index++
  198. }
  199. if len(blocks) == 0 {
  200. break
  201. }
  202. if hasAllBlocks(api.eth.BlockChain(), blocks) {
  203. blocks = blocks[:0]
  204. continue
  205. }
  206. // Import the batch and reset the buffer
  207. if _, err := api.eth.BlockChain().InsertChain(blocks); err != nil {
  208. return false, fmt.Errorf("batch %d: failed to insert: %v", batch, err)
  209. }
  210. blocks = blocks[:0]
  211. }
  212. return true, nil
  213. }
  214. // DebugAPI is the collection of Ethereum full node APIs for debugging the
  215. // protocol.
  216. type DebugAPI struct {
  217. eth *Ethereum
  218. }
  219. // NewDebugAPI creates a new DebugAPI instance.
  220. func NewDebugAPI(eth *Ethereum) *DebugAPI {
  221. return &DebugAPI{eth: eth}
  222. }
  223. // DumpBlock retrieves the entire state of the database at a given block.
  224. func (api *DebugAPI) DumpBlock(blockNr rpc.BlockNumber) (state.Dump, error) {
  225. opts := &state.DumpConfig{
  226. OnlyWithAddresses: true,
  227. Max: AccountRangeMaxResults, // Sanity limit over RPC
  228. }
  229. if blockNr == rpc.PendingBlockNumber {
  230. // If we're dumping the pending state, we need to request
  231. // both the pending block as well as the pending state from
  232. // the miner and operate on those
  233. _, stateDb := api.eth.miner.Pending()
  234. return stateDb.RawDump(opts), nil
  235. }
  236. var block *types.Block
  237. if blockNr == rpc.LatestBlockNumber {
  238. block = api.eth.blockchain.CurrentBlock()
  239. } else if blockNr == rpc.FinalizedBlockNumber {
  240. block = api.eth.blockchain.CurrentFinalizedBlock()
  241. } else if blockNr == rpc.SafeBlockNumber {
  242. block = api.eth.blockchain.CurrentSafeBlock()
  243. } else {
  244. block = api.eth.blockchain.GetBlockByNumber(uint64(blockNr))
  245. }
  246. if block == nil {
  247. return state.Dump{}, fmt.Errorf("block #%d not found", blockNr)
  248. }
  249. stateDb, err := api.eth.BlockChain().StateAt(block.Root())
  250. if err != nil {
  251. return state.Dump{}, err
  252. }
  253. return stateDb.RawDump(opts), nil
  254. }
  255. // Preimage is a debug API function that returns the preimage for a sha3 hash, if known.
  256. func (api *DebugAPI) Preimage(ctx context.Context, hash common.Hash) (hexutil.Bytes, error) {
  257. if preimage := rawdb.ReadPreimage(api.eth.ChainDb(), hash); preimage != nil {
  258. return preimage, nil
  259. }
  260. return nil, errors.New("unknown preimage")
  261. }
  262. // BadBlockArgs represents the entries in the list returned when bad blocks are queried.
  263. type BadBlockArgs struct {
  264. Hash common.Hash `json:"hash"`
  265. Block map[string]interface{} `json:"block"`
  266. RLP string `json:"rlp"`
  267. }
  268. // GetBadBlocks returns a list of the last 'bad blocks' that the client has seen on the network
  269. // and returns them as a JSON list of block hashes.
  270. func (api *DebugAPI) GetBadBlocks(ctx context.Context) ([]*BadBlockArgs, error) {
  271. var (
  272. err error
  273. blocks = rawdb.ReadAllBadBlocks(api.eth.chainDb)
  274. results = make([]*BadBlockArgs, 0, len(blocks))
  275. )
  276. for _, block := range blocks {
  277. var (
  278. blockRlp string
  279. blockJSON map[string]interface{}
  280. )
  281. if rlpBytes, err := rlp.EncodeToBytes(block); err != nil {
  282. blockRlp = err.Error() // Hacky, but hey, it works
  283. } else {
  284. blockRlp = fmt.Sprintf("%#x", rlpBytes)
  285. }
  286. if blockJSON, err = ethapi.RPCMarshalBlock(block, true, true, api.eth.APIBackend.ChainConfig()); err != nil {
  287. blockJSON = map[string]interface{}{"error": err.Error()}
  288. }
  289. results = append(results, &BadBlockArgs{
  290. Hash: block.Hash(),
  291. RLP: blockRlp,
  292. Block: blockJSON,
  293. })
  294. }
  295. return results, nil
  296. }
  297. // AccountRangeMaxResults is the maximum number of results to be returned per call
  298. const AccountRangeMaxResults = 256
  299. // AccountRange enumerates all accounts in the given block and start point in paging request
  300. func (api *DebugAPI) AccountRange(blockNrOrHash rpc.BlockNumberOrHash, start hexutil.Bytes, maxResults int, nocode, nostorage, incompletes bool) (state.IteratorDump, error) {
  301. var stateDb *state.StateDB
  302. var err error
  303. if number, ok := blockNrOrHash.Number(); ok {
  304. if number == rpc.PendingBlockNumber {
  305. // If we're dumping the pending state, we need to request
  306. // both the pending block as well as the pending state from
  307. // the miner and operate on those
  308. _, stateDb = api.eth.miner.Pending()
  309. } else {
  310. var block *types.Block
  311. if number == rpc.LatestBlockNumber {
  312. block = api.eth.blockchain.CurrentBlock()
  313. } else if number == rpc.FinalizedBlockNumber {
  314. block = api.eth.blockchain.CurrentFinalizedBlock()
  315. } else if number == rpc.SafeBlockNumber {
  316. block = api.eth.blockchain.CurrentSafeBlock()
  317. } else {
  318. block = api.eth.blockchain.GetBlockByNumber(uint64(number))
  319. }
  320. if block == nil {
  321. return state.IteratorDump{}, fmt.Errorf("block #%d not found", number)
  322. }
  323. stateDb, err = api.eth.BlockChain().StateAt(block.Root())
  324. if err != nil {
  325. return state.IteratorDump{}, err
  326. }
  327. }
  328. } else if hash, ok := blockNrOrHash.Hash(); ok {
  329. block := api.eth.blockchain.GetBlockByHash(hash)
  330. if block == nil {
  331. return state.IteratorDump{}, fmt.Errorf("block %s not found", hash.Hex())
  332. }
  333. stateDb, err = api.eth.BlockChain().StateAt(block.Root())
  334. if err != nil {
  335. return state.IteratorDump{}, err
  336. }
  337. } else {
  338. return state.IteratorDump{}, errors.New("either block number or block hash must be specified")
  339. }
  340. opts := &state.DumpConfig{
  341. SkipCode: nocode,
  342. SkipStorage: nostorage,
  343. OnlyWithAddresses: !incompletes,
  344. Start: start,
  345. Max: uint64(maxResults),
  346. }
  347. if maxResults > AccountRangeMaxResults || maxResults <= 0 {
  348. opts.Max = AccountRangeMaxResults
  349. }
  350. return stateDb.IteratorDump(opts), nil
  351. }
  352. // StorageRangeResult is the result of a debug_storageRangeAt API call.
  353. type StorageRangeResult struct {
  354. Storage storageMap `json:"storage"`
  355. NextKey *common.Hash `json:"nextKey"` // nil if Storage includes the last key in the trie.
  356. }
  357. type storageMap map[common.Hash]storageEntry
  358. type storageEntry struct {
  359. Key *common.Hash `json:"key"`
  360. Value common.Hash `json:"value"`
  361. }
  362. // StorageRangeAt returns the storage at the given block height and transaction index.
  363. func (api *DebugAPI) StorageRangeAt(blockHash common.Hash, txIndex int, contractAddress common.Address, keyStart hexutil.Bytes, maxResult int) (StorageRangeResult, error) {
  364. // Retrieve the block
  365. block := api.eth.blockchain.GetBlockByHash(blockHash)
  366. if block == nil {
  367. return StorageRangeResult{}, fmt.Errorf("block %#x not found", blockHash)
  368. }
  369. _, _, statedb, err := api.eth.stateAtTransaction(block, txIndex, 0)
  370. if err != nil {
  371. return StorageRangeResult{}, err
  372. }
  373. st := statedb.StorageTrie(contractAddress)
  374. if st == nil {
  375. return StorageRangeResult{}, fmt.Errorf("account %x doesn't exist", contractAddress)
  376. }
  377. return storageRangeAt(st, keyStart, maxResult)
  378. }
  379. func storageRangeAt(st state.Trie, start []byte, maxResult int) (StorageRangeResult, error) {
  380. it := trie.NewIterator(st.NodeIterator(start))
  381. result := StorageRangeResult{Storage: storageMap{}}
  382. for i := 0; i < maxResult && it.Next(); i++ {
  383. _, content, _, err := rlp.Split(it.Value)
  384. if err != nil {
  385. return StorageRangeResult{}, err
  386. }
  387. e := storageEntry{Value: common.BytesToHash(content)}
  388. if preimage := st.GetKey(it.Key); preimage != nil {
  389. preimage := common.BytesToHash(preimage)
  390. e.Key = &preimage
  391. }
  392. result.Storage[common.BytesToHash(it.Key)] = e
  393. }
  394. // Add the 'next key' so clients can continue downloading.
  395. if it.Next() {
  396. next := common.BytesToHash(it.Key)
  397. result.NextKey = &next
  398. }
  399. return result, nil
  400. }
  401. // GetModifiedAccountsByNumber returns all accounts that have changed between the
  402. // two blocks specified. A change is defined as a difference in nonce, balance,
  403. // code hash, or storage hash.
  404. //
  405. // With one parameter, returns the list of accounts modified in the specified block.
  406. func (api *DebugAPI) GetModifiedAccountsByNumber(startNum uint64, endNum *uint64) ([]common.Address, error) {
  407. var startBlock, endBlock *types.Block
  408. startBlock = api.eth.blockchain.GetBlockByNumber(startNum)
  409. if startBlock == nil {
  410. return nil, fmt.Errorf("start block %x not found", startNum)
  411. }
  412. if endNum == nil {
  413. endBlock = startBlock
  414. startBlock = api.eth.blockchain.GetBlockByHash(startBlock.ParentHash())
  415. if startBlock == nil {
  416. return nil, fmt.Errorf("block %x has no parent", endBlock.Number())
  417. }
  418. } else {
  419. endBlock = api.eth.blockchain.GetBlockByNumber(*endNum)
  420. if endBlock == nil {
  421. return nil, fmt.Errorf("end block %d not found", *endNum)
  422. }
  423. }
  424. return api.getModifiedAccounts(startBlock, endBlock)
  425. }
  426. // GetModifiedAccountsByHash returns all accounts that have changed between the
  427. // two blocks specified. A change is defined as a difference in nonce, balance,
  428. // code hash, or storage hash.
  429. //
  430. // With one parameter, returns the list of accounts modified in the specified block.
  431. func (api *DebugAPI) GetModifiedAccountsByHash(startHash common.Hash, endHash *common.Hash) ([]common.Address, error) {
  432. var startBlock, endBlock *types.Block
  433. startBlock = api.eth.blockchain.GetBlockByHash(startHash)
  434. if startBlock == nil {
  435. return nil, fmt.Errorf("start block %x not found", startHash)
  436. }
  437. if endHash == nil {
  438. endBlock = startBlock
  439. startBlock = api.eth.blockchain.GetBlockByHash(startBlock.ParentHash())
  440. if startBlock == nil {
  441. return nil, fmt.Errorf("block %x has no parent", endBlock.Number())
  442. }
  443. } else {
  444. endBlock = api.eth.blockchain.GetBlockByHash(*endHash)
  445. if endBlock == nil {
  446. return nil, fmt.Errorf("end block %x not found", *endHash)
  447. }
  448. }
  449. return api.getModifiedAccounts(startBlock, endBlock)
  450. }
  451. func (api *DebugAPI) getModifiedAccounts(startBlock, endBlock *types.Block) ([]common.Address, error) {
  452. if startBlock.Number().Uint64() >= endBlock.Number().Uint64() {
  453. return nil, fmt.Errorf("start block height (%d) must be less than end block height (%d)", startBlock.Number().Uint64(), endBlock.Number().Uint64())
  454. }
  455. triedb := api.eth.BlockChain().StateCache().TrieDB()
  456. oldTrie, err := trie.NewStateTrie(common.Hash{}, startBlock.Root(), triedb)
  457. if err != nil {
  458. return nil, err
  459. }
  460. newTrie, err := trie.NewStateTrie(common.Hash{}, endBlock.Root(), triedb)
  461. if err != nil {
  462. return nil, err
  463. }
  464. diff, _ := trie.NewDifferenceIterator(oldTrie.NodeIterator([]byte{}), newTrie.NodeIterator([]byte{}))
  465. iter := trie.NewIterator(diff)
  466. var dirty []common.Address
  467. for iter.Next() {
  468. key := newTrie.GetKey(iter.Key)
  469. if key == nil {
  470. return nil, fmt.Errorf("no preimage found for hash %x", iter.Key)
  471. }
  472. dirty = append(dirty, common.BytesToAddress(key))
  473. }
  474. return dirty, nil
  475. }
  476. // GetAccessibleState returns the first number where the node has accessible
  477. // state on disk. Note this being the post-state of that block and the pre-state
  478. // of the next block.
  479. // The (from, to) parameters are the sequence of blocks to search, which can go
  480. // either forwards or backwards
  481. func (api *DebugAPI) GetAccessibleState(from, to rpc.BlockNumber) (uint64, error) {
  482. db := api.eth.ChainDb()
  483. var pivot uint64
  484. if p := rawdb.ReadLastPivotNumber(db); p != nil {
  485. pivot = *p
  486. log.Info("Found fast-sync pivot marker", "number", pivot)
  487. }
  488. var resolveNum = func(num rpc.BlockNumber) (uint64, error) {
  489. // We don't have state for pending (-2), so treat it as latest
  490. if num.Int64() < 0 {
  491. block := api.eth.blockchain.CurrentBlock()
  492. if block == nil {
  493. return 0, fmt.Errorf("current block missing")
  494. }
  495. return block.NumberU64(), nil
  496. }
  497. return uint64(num.Int64()), nil
  498. }
  499. var (
  500. start uint64
  501. end uint64
  502. delta = int64(1)
  503. lastLog time.Time
  504. err error
  505. )
  506. if start, err = resolveNum(from); err != nil {
  507. return 0, err
  508. }
  509. if end, err = resolveNum(to); err != nil {
  510. return 0, err
  511. }
  512. if start == end {
  513. return 0, fmt.Errorf("from and to needs to be different")
  514. }
  515. if start > end {
  516. delta = -1
  517. }
  518. for i := int64(start); i != int64(end); i += delta {
  519. if time.Since(lastLog) > 8*time.Second {
  520. log.Info("Finding roots", "from", start, "to", end, "at", i)
  521. lastLog = time.Now()
  522. }
  523. if i < int64(pivot) {
  524. continue
  525. }
  526. h := api.eth.BlockChain().GetHeaderByNumber(uint64(i))
  527. if h == nil {
  528. return 0, fmt.Errorf("missing header %d", i)
  529. }
  530. if ok, _ := api.eth.ChainDb().Has(h.Root[:]); ok {
  531. return uint64(i), nil
  532. }
  533. }
  534. return 0, errors.New("no state found")
  535. }