2019-07-22 09:17:27 +00:00
|
|
|
// Copyright 2019 The go-ethereum Authors
|
2019-02-26 11:32:48 +00:00
|
|
|
// 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"
|
2019-11-13 22:47:03 +00:00
|
|
|
"fmt"
|
|
|
|
"time"
|
2019-02-26 11:32:48 +00:00
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
2019-11-13 22:47:03 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common/mclock"
|
2021-02-19 13:44:16 +00:00
|
|
|
vfs "github.com/ethereum/go-ethereum/les/vflux/server"
|
2019-11-13 22:47:03 +00:00
|
|
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
2019-02-26 11:32:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2019-11-13 22:47:03 +00:00
|
|
|
errNoCheckpoint = errors.New("no local checkpoint provided")
|
|
|
|
errNotActivated = errors.New("checkpoint registrar is not activated")
|
|
|
|
errUnknownBenchmarkType = errors.New("unknown benchmark type")
|
2019-02-26 11:32:48 +00:00
|
|
|
)
|
|
|
|
|
2022-06-21 09:05:43 +00:00
|
|
|
// LightServerAPI provides an API to access the LES light server.
|
|
|
|
type LightServerAPI struct {
|
2019-11-13 22:47:03 +00:00
|
|
|
server *LesServer
|
2021-02-19 13:44:16 +00:00
|
|
|
defaultPosFactors, defaultNegFactors vfs.PriceFactors
|
2019-11-13 22:47:03 +00:00
|
|
|
}
|
|
|
|
|
2022-06-21 09:05:43 +00:00
|
|
|
// NewLightServerAPI creates a new LES light server API.
|
|
|
|
func NewLightServerAPI(server *LesServer) *LightServerAPI {
|
|
|
|
return &LightServerAPI{
|
2019-11-13 22:47:03 +00:00
|
|
|
server: server,
|
2021-04-06 18:42:50 +00:00
|
|
|
defaultPosFactors: defaultPosFactors,
|
|
|
|
defaultNegFactors: defaultNegFactors,
|
2019-11-13 22:47:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-16 11:55:43 +00:00
|
|
|
// parseNode parses either an enode address a raw hex node id
|
|
|
|
func parseNode(node string) (enode.ID, error) {
|
|
|
|
if id, err := enode.ParseID(node); err == nil {
|
|
|
|
return id, nil
|
|
|
|
}
|
|
|
|
if node, err := enode.Parse(enode.ValidSchemes, node); err == nil {
|
|
|
|
return node.ID(), nil
|
|
|
|
} else {
|
|
|
|
return enode.ID{}, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-13 22:47:03 +00:00
|
|
|
// ServerInfo returns global server parameters
|
2022-06-21 09:05:43 +00:00
|
|
|
func (api *LightServerAPI) ServerInfo() map[string]interface{} {
|
2019-11-13 22:47:03 +00:00
|
|
|
res := make(map[string]interface{})
|
|
|
|
res["minimumCapacity"] = api.server.minCapacity
|
|
|
|
res["maximumCapacity"] = api.server.maxCapacity
|
2021-04-06 18:42:50 +00:00
|
|
|
_, res["totalCapacity"] = api.server.clientPool.Limits()
|
|
|
|
_, res["totalConnectedCapacity"] = api.server.clientPool.Active()
|
|
|
|
res["priorityConnectedCapacity"] = 0 //TODO connect when token sale module is added
|
2019-11-13 22:47:03 +00:00
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
|
|
|
// ClientInfo returns information about clients listed in the ids list or matching the given tags
|
2022-06-21 09:05:43 +00:00
|
|
|
func (api *LightServerAPI) ClientInfo(nodes []string) map[enode.ID]map[string]interface{} {
|
2021-03-16 11:55:43 +00:00
|
|
|
var ids []enode.ID
|
|
|
|
for _, node := range nodes {
|
|
|
|
if id, err := parseNode(node); err == nil {
|
|
|
|
ids = append(ids, id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-13 22:47:03 +00:00
|
|
|
res := make(map[enode.ID]map[string]interface{})
|
2021-04-06 18:42:50 +00:00
|
|
|
if len(ids) == 0 {
|
|
|
|
ids = api.server.peers.ids()
|
|
|
|
}
|
|
|
|
for _, id := range ids {
|
|
|
|
if peer := api.server.peers.peer(id); peer != nil {
|
|
|
|
res[id] = api.clientInfo(peer, peer.balance)
|
|
|
|
} else {
|
|
|
|
api.server.clientPool.BalanceOperation(id, "", func(balance vfs.AtomicBalanceOperator) {
|
|
|
|
res[id] = api.clientInfo(nil, balance)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2019-11-13 22:47:03 +00:00
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
|
|
|
// PriorityClientInfo returns information about clients with a positive balance
|
|
|
|
// in the given ID range (stop excluded). If stop is null then the iterator stops
|
|
|
|
// only at the end of the ID space. MaxCount limits the number of results returned.
|
|
|
|
// If maxCount limit is applied but there are more potential results then the ID
|
|
|
|
// of the next potential result is included in the map with an empty structure
|
|
|
|
// assigned to it.
|
2022-06-21 09:05:43 +00:00
|
|
|
func (api *LightServerAPI) PriorityClientInfo(start, stop enode.ID, maxCount int) map[enode.ID]map[string]interface{} {
|
2019-11-13 22:47:03 +00:00
|
|
|
res := make(map[enode.ID]map[string]interface{})
|
2021-04-06 18:42:50 +00:00
|
|
|
ids := api.server.clientPool.GetPosBalanceIDs(start, stop, maxCount+1)
|
2019-11-13 22:47:03 +00:00
|
|
|
if len(ids) > maxCount {
|
|
|
|
res[ids[maxCount]] = make(map[string]interface{})
|
|
|
|
ids = ids[:maxCount]
|
|
|
|
}
|
2021-04-06 18:42:50 +00:00
|
|
|
for _, id := range ids {
|
|
|
|
if peer := api.server.peers.peer(id); peer != nil {
|
|
|
|
res[id] = api.clientInfo(peer, peer.balance)
|
|
|
|
} else {
|
|
|
|
api.server.clientPool.BalanceOperation(id, "", func(balance vfs.AtomicBalanceOperator) {
|
|
|
|
res[id] = api.clientInfo(nil, balance)
|
|
|
|
})
|
|
|
|
}
|
2019-11-13 22:47:03 +00:00
|
|
|
}
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
|
|
|
// clientInfo creates a client info data structure
|
2022-06-21 09:05:43 +00:00
|
|
|
func (api *LightServerAPI) clientInfo(peer *clientPeer, balance vfs.ReadOnlyBalance) map[string]interface{} {
|
2019-11-13 22:47:03 +00:00
|
|
|
info := make(map[string]interface{})
|
2021-04-06 18:42:50 +00:00
|
|
|
pb, nb := balance.GetBalance()
|
|
|
|
info["isConnected"] = peer != nil
|
2020-09-14 20:44:20 +00:00
|
|
|
info["pricing/balance"] = pb
|
|
|
|
info["priority"] = pb != 0
|
|
|
|
// cb := api.server.clientPool.ndb.getCurrencyBalance(id)
|
|
|
|
// info["pricing/currency"] = cb.amount
|
2021-04-06 18:42:50 +00:00
|
|
|
if peer != nil {
|
|
|
|
info["connectionTime"] = float64(mclock.Now()-peer.connectedAt) / float64(time.Second)
|
|
|
|
info["capacity"] = peer.getCapacity()
|
2020-09-14 20:44:20 +00:00
|
|
|
info["pricing/negBalance"] = nb
|
2019-11-13 22:47:03 +00:00
|
|
|
}
|
|
|
|
return info
|
|
|
|
}
|
|
|
|
|
|
|
|
// setParams either sets the given parameters for a single connected client (if specified)
|
|
|
|
// or the default parameters applicable to clients connected in the future
|
2022-06-21 09:05:43 +00:00
|
|
|
func (api *LightServerAPI) setParams(params map[string]interface{}, client *clientPeer, posFactors, negFactors *vfs.PriceFactors) (updateFactors bool, err error) {
|
2019-11-13 22:47:03 +00:00
|
|
|
defParams := client == nil
|
|
|
|
for name, value := range params {
|
|
|
|
errValue := func() error {
|
|
|
|
return fmt.Errorf("invalid value for parameter '%s'", name)
|
|
|
|
}
|
|
|
|
setFactor := func(v *float64) {
|
|
|
|
if val, ok := value.(float64); ok && val >= 0 {
|
|
|
|
*v = val / float64(time.Second)
|
|
|
|
updateFactors = true
|
|
|
|
} else {
|
|
|
|
err = errValue()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch {
|
|
|
|
case name == "pricing/timeFactor":
|
2020-09-14 20:44:20 +00:00
|
|
|
setFactor(&posFactors.TimeFactor)
|
2019-11-13 22:47:03 +00:00
|
|
|
case name == "pricing/capacityFactor":
|
2020-09-14 20:44:20 +00:00
|
|
|
setFactor(&posFactors.CapacityFactor)
|
2019-11-13 22:47:03 +00:00
|
|
|
case name == "pricing/requestCostFactor":
|
2020-09-14 20:44:20 +00:00
|
|
|
setFactor(&posFactors.RequestFactor)
|
2019-11-13 22:47:03 +00:00
|
|
|
case name == "pricing/negative/timeFactor":
|
2020-09-14 20:44:20 +00:00
|
|
|
setFactor(&negFactors.TimeFactor)
|
2019-11-13 22:47:03 +00:00
|
|
|
case name == "pricing/negative/capacityFactor":
|
2020-09-14 20:44:20 +00:00
|
|
|
setFactor(&negFactors.CapacityFactor)
|
2019-11-13 22:47:03 +00:00
|
|
|
case name == "pricing/negative/requestCostFactor":
|
2020-09-14 20:44:20 +00:00
|
|
|
setFactor(&negFactors.RequestFactor)
|
2019-11-13 22:47:03 +00:00
|
|
|
case !defParams && name == "capacity":
|
|
|
|
if capacity, ok := value.(float64); ok && uint64(capacity) >= api.server.minCapacity {
|
2021-04-06 18:42:50 +00:00
|
|
|
_, err = api.server.clientPool.SetCapacity(client.Node(), uint64(capacity), 0, false)
|
|
|
|
// time factor recalculation is performed automatically by the balance tracker
|
2019-11-13 22:47:03 +00:00
|
|
|
} else {
|
|
|
|
err = errValue()
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
if defParams {
|
|
|
|
err = fmt.Errorf("invalid default parameter '%s'", name)
|
|
|
|
} else {
|
|
|
|
err = fmt.Errorf("invalid client parameter '%s'", name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetClientParams sets client parameters for all clients listed in the ids list
|
|
|
|
// or all connected clients if the list is empty
|
2022-06-21 09:05:43 +00:00
|
|
|
func (api *LightServerAPI) SetClientParams(nodes []string, params map[string]interface{}) error {
|
2021-04-06 18:42:50 +00:00
|
|
|
var err error
|
2021-03-16 11:55:43 +00:00
|
|
|
for _, node := range nodes {
|
2021-04-06 18:42:50 +00:00
|
|
|
var id enode.ID
|
|
|
|
if id, err = parseNode(node); err != nil {
|
2021-03-16 11:55:43 +00:00
|
|
|
return err
|
|
|
|
}
|
2021-04-06 18:42:50 +00:00
|
|
|
if peer := api.server.peers.peer(id); peer != nil {
|
|
|
|
posFactors, negFactors := peer.balance.GetPriceFactors()
|
|
|
|
update, e := api.setParams(params, peer, &posFactors, &negFactors)
|
2019-11-13 22:47:03 +00:00
|
|
|
if update {
|
2021-04-06 18:42:50 +00:00
|
|
|
peer.balance.SetPriceFactors(posFactors, negFactors)
|
2020-09-14 20:44:20 +00:00
|
|
|
}
|
|
|
|
if e != nil {
|
|
|
|
err = e
|
2019-11-13 22:47:03 +00:00
|
|
|
}
|
|
|
|
} else {
|
2021-04-06 18:42:50 +00:00
|
|
|
err = fmt.Errorf("client %064x is not connected", id)
|
2019-11-13 22:47:03 +00:00
|
|
|
}
|
2021-04-06 18:42:50 +00:00
|
|
|
}
|
2020-09-14 20:44:20 +00:00
|
|
|
return err
|
2019-11-13 22:47:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetDefaultParams sets the default parameters applicable to clients connected in the future
|
2022-06-21 09:05:43 +00:00
|
|
|
func (api *LightServerAPI) SetDefaultParams(params map[string]interface{}) error {
|
2019-11-13 22:47:03 +00:00
|
|
|
update, err := api.setParams(params, nil, &api.defaultPosFactors, &api.defaultNegFactors)
|
|
|
|
if update {
|
2021-04-06 18:42:50 +00:00
|
|
|
api.server.clientPool.SetDefaultFactors(api.defaultPosFactors, api.defaultNegFactors)
|
2019-11-13 22:47:03 +00:00
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-07-21 08:23:40 +00:00
|
|
|
// SetConnectedBias set the connection bias, which is applied to already connected clients
|
|
|
|
// So that already connected client won't be kicked out very soon and we can ensure all
|
|
|
|
// connected clients can have enough time to request or sync some data.
|
|
|
|
// When the input parameter `bias` < 0 (illegal), return error.
|
2022-06-21 09:05:43 +00:00
|
|
|
func (api *LightServerAPI) SetConnectedBias(bias time.Duration) error {
|
2020-07-21 08:23:40 +00:00
|
|
|
if bias < time.Duration(0) {
|
|
|
|
return fmt.Errorf("bias illegal: %v less than 0", bias)
|
|
|
|
}
|
2021-04-06 18:42:50 +00:00
|
|
|
api.server.clientPool.SetConnectedBias(bias)
|
2020-07-21 08:23:40 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-09-14 20:44:20 +00:00
|
|
|
// AddBalance adds the given amount to the balance of a client if possible and returns
|
|
|
|
// the balance before and after the operation
|
2022-06-21 09:05:43 +00:00
|
|
|
func (api *LightServerAPI) AddBalance(node string, amount int64) (balance [2]uint64, err error) {
|
2021-03-16 11:55:43 +00:00
|
|
|
var id enode.ID
|
|
|
|
if id, err = parseNode(node); err != nil {
|
|
|
|
return
|
|
|
|
}
|
2021-04-06 18:42:50 +00:00
|
|
|
api.server.clientPool.BalanceOperation(id, "", func(nb vfs.AtomicBalanceOperator) {
|
|
|
|
balance[0], balance[1], err = nb.AddBalance(amount)
|
2020-09-14 20:44:20 +00:00
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-11-13 22:47:03 +00:00
|
|
|
// Benchmark runs a request performance benchmark with a given set of measurement setups
|
|
|
|
// in multiple passes specified by passCount. The measurement time for each setup in each
|
|
|
|
// pass is specified in milliseconds by length.
|
|
|
|
//
|
|
|
|
// Note: measurement time is adjusted for each pass depending on the previous ones.
|
|
|
|
// Therefore a controlled total measurement time is achievable in multiple passes.
|
2022-06-21 09:05:43 +00:00
|
|
|
func (api *LightServerAPI) Benchmark(setups []map[string]interface{}, passCount, length int) ([]map[string]interface{}, error) {
|
2019-11-13 22:47:03 +00:00
|
|
|
benchmarks := make([]requestBenchmark, len(setups))
|
|
|
|
for i, setup := range setups {
|
|
|
|
if t, ok := setup["type"].(string); ok {
|
|
|
|
getInt := func(field string, def int) int {
|
|
|
|
if value, ok := setup[field].(float64); ok {
|
|
|
|
return int(value)
|
|
|
|
}
|
|
|
|
return def
|
|
|
|
}
|
|
|
|
getBool := func(field string, def bool) bool {
|
|
|
|
if value, ok := setup[field].(bool); ok {
|
|
|
|
return value
|
|
|
|
}
|
|
|
|
return def
|
|
|
|
}
|
|
|
|
switch t {
|
|
|
|
case "header":
|
|
|
|
benchmarks[i] = &benchmarkBlockHeaders{
|
|
|
|
amount: getInt("amount", 1),
|
|
|
|
skip: getInt("skip", 1),
|
|
|
|
byHash: getBool("byHash", false),
|
|
|
|
reverse: getBool("reverse", false),
|
|
|
|
}
|
|
|
|
case "body":
|
|
|
|
benchmarks[i] = &benchmarkBodiesOrReceipts{receipts: false}
|
|
|
|
case "receipts":
|
|
|
|
benchmarks[i] = &benchmarkBodiesOrReceipts{receipts: true}
|
|
|
|
case "proof":
|
|
|
|
benchmarks[i] = &benchmarkProofsOrCode{code: false}
|
|
|
|
case "code":
|
|
|
|
benchmarks[i] = &benchmarkProofsOrCode{code: true}
|
|
|
|
case "cht":
|
|
|
|
benchmarks[i] = &benchmarkHelperTrie{
|
|
|
|
bloom: false,
|
|
|
|
reqCount: getInt("amount", 1),
|
|
|
|
}
|
|
|
|
case "bloom":
|
|
|
|
benchmarks[i] = &benchmarkHelperTrie{
|
|
|
|
bloom: true,
|
|
|
|
reqCount: getInt("amount", 1),
|
|
|
|
}
|
|
|
|
case "txSend":
|
|
|
|
benchmarks[i] = &benchmarkTxSend{}
|
|
|
|
case "txStatus":
|
|
|
|
benchmarks[i] = &benchmarkTxStatus{}
|
|
|
|
default:
|
|
|
|
return nil, errUnknownBenchmarkType
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return nil, errUnknownBenchmarkType
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rs := api.server.handler.runBenchmark(benchmarks, passCount, time.Millisecond*time.Duration(length))
|
|
|
|
result := make([]map[string]interface{}, len(setups))
|
|
|
|
for i, r := range rs {
|
|
|
|
res := make(map[string]interface{})
|
|
|
|
if r.err == nil {
|
|
|
|
res["totalCount"] = r.totalCount
|
|
|
|
res["avgTime"] = r.avgTime
|
|
|
|
res["maxInSize"] = r.maxInSize
|
|
|
|
res["maxOutSize"] = r.maxOutSize
|
|
|
|
} else {
|
|
|
|
res["error"] = r.err.Error()
|
|
|
|
}
|
|
|
|
result[i] = res
|
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2022-06-21 09:05:43 +00:00
|
|
|
// DebugAPI provides an API to debug LES light server functionality.
|
|
|
|
type DebugAPI struct {
|
2019-11-13 22:47:03 +00:00
|
|
|
server *LesServer
|
|
|
|
}
|
|
|
|
|
2022-06-21 09:05:43 +00:00
|
|
|
// NewDebugAPI creates a new LES light server debug API.
|
|
|
|
func NewDebugAPI(server *LesServer) *DebugAPI {
|
|
|
|
return &DebugAPI{
|
2019-11-13 22:47:03 +00:00
|
|
|
server: server,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FreezeClient forces a temporary client freeze which normally happens when the server is overloaded
|
2022-06-21 09:05:43 +00:00
|
|
|
func (api *DebugAPI) FreezeClient(node string) error {
|
2021-03-16 11:55:43 +00:00
|
|
|
var (
|
|
|
|
id enode.ID
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
if id, err = parseNode(node); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-04-06 18:42:50 +00:00
|
|
|
if peer := api.server.peers.peer(id); peer != nil {
|
|
|
|
peer.freeze()
|
|
|
|
return nil
|
|
|
|
} else {
|
|
|
|
return fmt.Errorf("client %064x is not connected", id[:])
|
|
|
|
}
|
2019-11-13 22:47:03 +00:00
|
|
|
}
|
|
|
|
|
2022-06-21 09:05:43 +00:00
|
|
|
// LightAPI provides an API to access the LES light server or light client.
|
|
|
|
type LightAPI struct {
|
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 07:34:02 +00:00
|
|
|
backend *lesCommons
|
|
|
|
}
|
|
|
|
|
2022-06-21 09:05:43 +00:00
|
|
|
// NewLightAPI creates a new LES service API.
|
|
|
|
func NewLightAPI(backend *lesCommons) *LightAPI {
|
|
|
|
return &LightAPI{backend: backend}
|
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 07:34:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// LatestCheckpoint returns the latest local checkpoint package.
|
|
|
|
//
|
|
|
|
// The checkpoint package consists of 4 strings:
|
2022-09-10 11:25:40 +00:00
|
|
|
//
|
|
|
|
// 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
|
2022-06-21 09:05:43 +00:00
|
|
|
func (api *LightAPI) LatestCheckpoint() ([4]string, error) {
|
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 07:34:02 +00:00
|
|
|
var res [4]string
|
|
|
|
cp := api.backend.latestLocalCheckpoint()
|
|
|
|
if cp.Empty() {
|
2019-07-03 18:23:06 +00: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 07:34:02 +00: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:
|
2022-09-10 11:25:40 +00:00
|
|
|
//
|
|
|
|
// 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
|
2022-06-21 09:05:43 +00:00
|
|
|
func (api *LightAPI) GetCheckpoint(index uint64) ([3]string, error) {
|
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 07:34:02 +00:00
|
|
|
var res [3]string
|
2019-08-21 09:29:34 +00:00
|
|
|
cp := api.backend.localCheckpoint(index)
|
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 07:34:02 +00:00
|
|
|
if cp.Empty() {
|
2019-07-03 18:23:06 +00: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 07:34:02 +00: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.
|
2022-06-21 09:05:43 +00:00
|
|
|
func (api *LightAPI) GetCheckpointContractAddress() (string, error) {
|
2019-08-21 09:29:34 +00:00
|
|
|
if api.backend.oracle == nil {
|
2019-07-03 18:23:06 +00: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 07:34:02 +00:00
|
|
|
}
|
2020-01-07 09:24:21 +00:00
|
|
|
return api.backend.oracle.Contract().ContractAddr().Hex(), nil
|
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 07:34:02 +00:00
|
|
|
}
|