mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
[NOD-151] Removed VerifyDAG RPC API (#272)
This commit is contained in:
parent
e9ec8cd39c
commit
8683258e4a
@ -717,24 +717,6 @@ func NewValidateAddressCmd(address string) *ValidateAddressCmd {
|
||||
}
|
||||
}
|
||||
|
||||
// VerifyDAGCmd defines the verifyDag JSON-RPC command.
|
||||
type VerifyDAGCmd struct {
|
||||
CheckLevel *uint64 `jsonrpcdefault:"3"`
|
||||
CheckDepth *uint64 `jsonrpcdefault:"288"` // 0 = all
|
||||
}
|
||||
|
||||
// NewVerifyDAGCmd returns a new instance which can be used to issue a
|
||||
// verifyDag JSON-RPC command.
|
||||
//
|
||||
// The parameters which are pointers indicate they are optional. Passing nil
|
||||
// for optional parameters will use the default value.
|
||||
func NewVerifyDAGCmd(checkLevel, checkDepth *uint64) *VerifyDAGCmd {
|
||||
return &VerifyDAGCmd{
|
||||
CheckLevel: checkLevel,
|
||||
CheckDepth: checkDepth,
|
||||
}
|
||||
}
|
||||
|
||||
// VerifyMessageCmd defines the verifyMessage JSON-RPC command.
|
||||
type VerifyMessageCmd struct {
|
||||
Address string
|
||||
@ -815,7 +797,6 @@ func init() {
|
||||
MustRegisterCmd("submitBlock", (*SubmitBlockCmd)(nil), flags)
|
||||
MustRegisterCmd("uptime", (*UptimeCmd)(nil), flags)
|
||||
MustRegisterCmd("validateAddress", (*ValidateAddressCmd)(nil), flags)
|
||||
MustRegisterCmd("verifyDag", (*VerifyDAGCmd)(nil), flags)
|
||||
MustRegisterCmd("verifyMessage", (*VerifyMessageCmd)(nil), flags)
|
||||
MustRegisterCmd("verifyTxOutProof", (*VerifyTxOutProofCmd)(nil), flags)
|
||||
}
|
||||
|
@ -1017,48 +1017,6 @@ func TestDAGSvrCmds(t *testing.T) {
|
||||
Address: "1Address",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "verifyDag",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("verifyDag")
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return btcjson.NewVerifyDAGCmd(nil, nil)
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"verifyDag","params":[],"id":1}`,
|
||||
unmarshalled: &btcjson.VerifyDAGCmd{
|
||||
CheckLevel: btcjson.Uint64(3),
|
||||
CheckDepth: btcjson.Uint64(288),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "verifyDag optional1",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("verifyDag", 2)
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return btcjson.NewVerifyDAGCmd(btcjson.Uint64(2), nil)
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"verifyDag","params":[2],"id":1}`,
|
||||
unmarshalled: &btcjson.VerifyDAGCmd{
|
||||
CheckLevel: btcjson.Uint64(2),
|
||||
CheckDepth: btcjson.Uint64(288),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "verifyDag optional2",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("verifyDag", 2, 500)
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return btcjson.NewVerifyDAGCmd(btcjson.Uint64(2), btcjson.Uint64(500))
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"verifyDag","params":[2,500],"id":1}`,
|
||||
unmarshalled: &btcjson.VerifyDAGCmd{
|
||||
CheckLevel: btcjson.Uint64(2),
|
||||
CheckDepth: btcjson.Uint64(500),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "verifyMessage",
|
||||
newCmd: func() (interface{}, error) {
|
||||
|
@ -594,95 +594,6 @@ func (c *Client) EstimateFee(numBlocks int64) (float64, error) {
|
||||
return c.EstimateFeeAsync(numBlocks).Receive()
|
||||
}
|
||||
|
||||
// FutureVerifyDAGResult is a future promise to deliver the result of a
|
||||
// VerifyDAGAsync, VerifyDAGLevelAsyncRPC, or VerifyDAGBlocksAsync
|
||||
// invocation (or an applicable error).
|
||||
type FutureVerifyDAGResult chan *response
|
||||
|
||||
// Receive waits for the response promised by the future and returns whether
|
||||
// or not the dag verified based on the check level and number of blocks
|
||||
// to verify specified in the original call.
|
||||
func (r FutureVerifyDAGResult) Receive() (bool, error) {
|
||||
res, err := receiveFuture(r)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// Unmarshal the result as a boolean.
|
||||
var verified bool
|
||||
err = json.Unmarshal(res, &verified)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return verified, nil
|
||||
}
|
||||
|
||||
// VerifyDAGAsync returns an instance of a type that can be used to get the
|
||||
// result of the RPC at some future time by invoking the Receive function on the
|
||||
// returned instance.
|
||||
//
|
||||
// See VerifyDAG for the blocking version and more details.
|
||||
func (c *Client) VerifyDAGAsync() FutureVerifyDAGResult {
|
||||
cmd := btcjson.NewVerifyDAGCmd(nil, nil)
|
||||
return c.sendCmd(cmd)
|
||||
}
|
||||
|
||||
// VerifyDAG requests the server to verify the block dag database using
|
||||
// the default check level and number of blocks to verify.
|
||||
//
|
||||
// See VerifyDAGLevel and VerifyDAGBlocks to override the defaults.
|
||||
func (c *Client) VerifyDAG() (bool, error) {
|
||||
return c.VerifyDAGAsync().Receive()
|
||||
}
|
||||
|
||||
// VerifyDAGLevelAsync returns an instance of a type that can be used to get
|
||||
// the result of the RPC at some future time by invoking the Receive function on
|
||||
// the returned instance.
|
||||
//
|
||||
// See VerifyDAGLevel for the blocking version and more details.
|
||||
func (c *Client) VerifyDAGLevelAsync(checkLevel uint64) FutureVerifyDAGResult {
|
||||
cmd := btcjson.NewVerifyDAGCmd(&checkLevel, nil)
|
||||
return c.sendCmd(cmd)
|
||||
}
|
||||
|
||||
// VerifyDAGLevel requests the server to verify the block dag database using
|
||||
// the passed check level and default number of blocks to verify.
|
||||
//
|
||||
// The check level controls how thorough the verification is with higher numbers
|
||||
// increasing the amount of checks done as consequently how long the
|
||||
// verification takes.
|
||||
//
|
||||
// See VerifyDAG to use the default check level and VerifyDAGBlocks to
|
||||
// override the number of blocks to verify.
|
||||
func (c *Client) VerifyDAGLevel(checkLevel uint64) (bool, error) {
|
||||
return c.VerifyDAGLevelAsync(checkLevel).Receive()
|
||||
}
|
||||
|
||||
// VerifyDAGBlocksAsync returns an instance of a type that can be used to get
|
||||
// the result of the RPC at some future time by invoking the Receive function on
|
||||
// the returned instance.
|
||||
//
|
||||
// See VerifyDAGBlocks for the blocking version and more details.
|
||||
func (c *Client) VerifyDAGBlocksAsync(checkLevel, numBlocks uint64) FutureVerifyDAGResult {
|
||||
cmd := btcjson.NewVerifyDAGCmd(&checkLevel, &numBlocks)
|
||||
return c.sendCmd(cmd)
|
||||
}
|
||||
|
||||
// VerifyDAGBlocks requests the server to verify the block dag database
|
||||
// using the passed check level and number of blocks to verify.
|
||||
//
|
||||
// The check level controls how thorough the verification is with higher numbers
|
||||
// increasing the amount of checks done as consequently how long the
|
||||
// verification takes.
|
||||
//
|
||||
// The number of blocks refers to the number of blocks from the end of the
|
||||
// current longest dag.
|
||||
//
|
||||
// See VerifyDAG and VerifyDAGLevel to use defaults.
|
||||
func (c *Client) VerifyDAGBlocks(checkLevel, numBlocks uint64) (bool, error) {
|
||||
return c.VerifyDAGBlocksAsync(checkLevel, numBlocks).Receive()
|
||||
}
|
||||
|
||||
// FutureGetTxOutResult is a future promise to deliver the result of a
|
||||
// GetTxOutAsync RPC invocation (or an applicable error).
|
||||
type FutureGetTxOutResult chan *response
|
||||
|
@ -183,7 +183,6 @@ var rpcHandlersBeforeInit = map[string]commandHandler{
|
||||
"submitBlock": handleSubmitBlock,
|
||||
"uptime": handleUptime,
|
||||
"validateAddress": handleValidateAddress,
|
||||
"verifyDag": handleVerifyDAG,
|
||||
"verifyMessage": handleVerifyMessage,
|
||||
"version": handleVersion,
|
||||
}
|
||||
@ -3476,58 +3475,6 @@ func handleValidateAddress(s *Server, cmd interface{}, closeChan <-chan struct{}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func verifyDAG(s *Server, level, depth uint64) error {
|
||||
finishHeight := s.cfg.DAG.Height() - depth //TODO: (Ori) This is probably wrong. Done only for compilation
|
||||
if finishHeight < 0 {
|
||||
finishHeight = 0
|
||||
}
|
||||
log.Infof("Verifying DAG for %d blocks at level %d",
|
||||
s.cfg.DAG.Height()-finishHeight, level) //TODO: (Ori) This is probably wrong. Done only for compilation
|
||||
|
||||
currentHash := s.cfg.DAG.HighestTipHash()
|
||||
for height := s.cfg.DAG.Height(); height > finishHeight; { //TODO: (Ori) This is probably wrong. Done only for compilation
|
||||
// Level 0 just looks up the block.
|
||||
block, err := s.cfg.DAG.BlockByHash(currentHash)
|
||||
if err != nil {
|
||||
log.Errorf("Verify is unable to fetch block at "+
|
||||
"height %d: %s", height, err)
|
||||
return err
|
||||
}
|
||||
|
||||
// Level 1 does basic DAG sanity checks.
|
||||
if level > 0 {
|
||||
err := s.cfg.DAG.CheckBlockSanity(block, s.cfg.DAGParams.PowLimit, s.cfg.TimeSource)
|
||||
if err != nil {
|
||||
log.Errorf("Verify is unable to validate "+
|
||||
"block at hash %s height %d: %s",
|
||||
block.Hash(), height, err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
currentHash = block.MsgBlock().Header.SelectedParentHash()
|
||||
}
|
||||
log.Infof("DAG verify completed successfully")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// handleVerifyDAG implements the verifyDag command.
|
||||
func handleVerifyDAG(s *Server, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
|
||||
c := cmd.(*btcjson.VerifyDAGCmd)
|
||||
|
||||
var checkLevel, checkDepth uint64
|
||||
if c.CheckLevel != nil {
|
||||
checkLevel = *c.CheckLevel
|
||||
}
|
||||
if c.CheckDepth != nil {
|
||||
checkDepth = *c.CheckDepth
|
||||
}
|
||||
|
||||
err := verifyDAG(s, checkLevel, checkDepth)
|
||||
return err == nil, nil
|
||||
}
|
||||
|
||||
// handleVerifyMessage implements the verifyMessage command.
|
||||
func handleVerifyMessage(s *Server, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
|
||||
c := cmd.(*btcjson.VerifyMessageCmd)
|
||||
|
@ -583,16 +583,6 @@ var helpDescsEnUS = map[string]string{
|
||||
"validateAddress--synopsis": "Verify an address is valid.",
|
||||
"validateAddress-address": "Bitcoin address to validate",
|
||||
|
||||
// VerifyChainCmd help.
|
||||
"verifyDag--synopsis": "Verifies the block DAG database.\n" +
|
||||
"The actual checks performed by the checkLevel parameter are implementation specific.\n" +
|
||||
"For btcd this is:\n" +
|
||||
"checkLevel=0 - Look up each block and ensure it can be loaded from the database.\n" +
|
||||
"checkLevel=1 - Perform basic context-free sanity checks on each block.",
|
||||
"verifyDag-checkLevel": "How thorough the block verification is",
|
||||
"verifyDag-checkDepth": "The number of blocks to check",
|
||||
"verifyDag--result0": "Whether or not the DAG verified",
|
||||
|
||||
// VerifyMessageCmd help.
|
||||
"verifyMessage--synopsis": "Verify a signed message.",
|
||||
"verifyMessage-address": "The bitcoin address to use for the signature",
|
||||
@ -735,7 +725,6 @@ var rpcResultTypes = map[string][]interface{}{
|
||||
"submitBlock": {nil, (*string)(nil)},
|
||||
"uptime": {(*int64)(nil)},
|
||||
"validateAddress": {(*btcjson.ValidateAddressResult)(nil)},
|
||||
"verifyDag": {(*bool)(nil)},
|
||||
"verifyMessage": {(*bool)(nil)},
|
||||
"version": {(*map[string]btcjson.VersionResult)(nil)},
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user