2019-02-26 14:32:48 +03:00
|
|
|
// Copyright 2018 The go-ethereum Authors
|
|
|
|
// This file is part of the go-ethereum library.
|
|
|
|
//
|
|
|
|
// The go-ethereum library 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.
|
|
|
|
//
|
|
|
|
// The go-ethereum library 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 the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package les
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2019-07-03 21:23:06 +03:00
|
|
|
errNoCheckpoint = errors.New("no local checkpoint provided")
|
|
|
|
errNotActivated = errors.New("checkpoint registrar is not activated")
|
2019-02-26 14:32:48 +03:00
|
|
|
)
|
|
|
|
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 10:34:02 +03:00
|
|
|
// PrivateLightAPI provides an API to access the LES light server or light client.
|
|
|
|
type PrivateLightAPI struct {
|
|
|
|
backend *lesCommons
|
|
|
|
reg *checkpointOracle
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewPrivateLightAPI creates a new LES service API.
|
|
|
|
func NewPrivateLightAPI(backend *lesCommons, reg *checkpointOracle) *PrivateLightAPI {
|
|
|
|
return &PrivateLightAPI{
|
|
|
|
backend: backend,
|
|
|
|
reg: reg,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// LatestCheckpoint returns the latest local checkpoint package.
|
|
|
|
//
|
|
|
|
// The checkpoint package consists of 4 strings:
|
|
|
|
// result[0], hex encoded latest section index
|
|
|
|
// result[1], 32 bytes hex encoded latest section head hash
|
|
|
|
// result[2], 32 bytes hex encoded latest section canonical hash trie root hash
|
|
|
|
// result[3], 32 bytes hex encoded latest section bloom trie root hash
|
|
|
|
func (api *PrivateLightAPI) LatestCheckpoint() ([4]string, error) {
|
|
|
|
var res [4]string
|
|
|
|
cp := api.backend.latestLocalCheckpoint()
|
|
|
|
if cp.Empty() {
|
2019-07-03 21:23:06 +03:00
|
|
|
return res, errNoCheckpoint
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 10:34:02 +03:00
|
|
|
}
|
|
|
|
res[0] = hexutil.EncodeUint64(cp.SectionIndex)
|
|
|
|
res[1], res[2], res[3] = cp.SectionHead.Hex(), cp.CHTRoot.Hex(), cp.BloomRoot.Hex()
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetLocalCheckpoint returns the specific local checkpoint package.
|
|
|
|
//
|
|
|
|
// The checkpoint package consists of 3 strings:
|
|
|
|
// result[0], 32 bytes hex encoded latest section head hash
|
|
|
|
// result[1], 32 bytes hex encoded latest section canonical hash trie root hash
|
|
|
|
// result[2], 32 bytes hex encoded latest section bloom trie root hash
|
|
|
|
func (api *PrivateLightAPI) GetCheckpoint(index uint64) ([3]string, error) {
|
|
|
|
var res [3]string
|
|
|
|
cp := api.backend.getLocalCheckpoint(index)
|
|
|
|
if cp.Empty() {
|
2019-07-03 21:23:06 +03:00
|
|
|
return res, errNoCheckpoint
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 10:34:02 +03:00
|
|
|
}
|
|
|
|
res[0], res[1], res[2] = cp.SectionHead.Hex(), cp.CHTRoot.Hex(), cp.BloomRoot.Hex()
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetCheckpointContractAddress returns the contract contract address in hex format.
|
|
|
|
func (api *PrivateLightAPI) GetCheckpointContractAddress() (string, error) {
|
|
|
|
if api.reg == nil {
|
2019-07-03 21:23:06 +03:00
|
|
|
return "", errNotActivated
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 10:34:02 +03:00
|
|
|
}
|
|
|
|
return api.reg.config.Address.Hex(), nil
|
|
|
|
}
|