mirror of
https://github.com/LBRYFoundation/lbcd.git
synced 2025-08-23 17:47:24 +00:00
Differentiate between basic/extended filters in p2p/RPC
This commit is contained in:
parent
f703e18652
commit
71c421db66
7 changed files with 33 additions and 19 deletions
|
@ -171,11 +171,15 @@ func (idx *CfIndex) DisconnectBlock(dbTx database.Tx, block *btcutil.Block,
|
||||||
return dbDeleteBasicEntry(dbTx, block.Hash())
|
return dbDeleteBasicEntry(dbTx, block.Hash())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (idx *CfIndex) FilterByBlockHash(hash *chainhash.Hash) ([]byte, error) {
|
func (idx *CfIndex) FilterByBlockHash(hash *chainhash.Hash, extended bool) ([]byte, error) {
|
||||||
var filterBytes []byte
|
var filterBytes []byte
|
||||||
err := idx.db.View(func(dbTx database.Tx) error {
|
err := idx.db.View(func(dbTx database.Tx) error {
|
||||||
var err error
|
var err error
|
||||||
filterBytes, err = dbFetchBasicEntry(dbTx, hash)
|
if extended {
|
||||||
|
filterBytes, err = dbFetchExtendedEntry(dbTx, hash)
|
||||||
|
} else {
|
||||||
|
filterBytes, err = dbFetchBasicEntry(dbTx, hash)
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
return filterBytes, err
|
return filterBytes, err
|
||||||
|
|
|
@ -280,14 +280,16 @@ func NewGetBlockTemplateCmd(request *TemplateRequest) *GetBlockTemplateCmd {
|
||||||
}
|
}
|
||||||
// GetCFilterCmd defines the getcfilter JSON-RPC command.
|
// GetCFilterCmd defines the getcfilter JSON-RPC command.
|
||||||
type GetCFilterCmd struct {
|
type GetCFilterCmd struct {
|
||||||
Hash string
|
Hash string
|
||||||
|
Extended bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewGetCFilterCmd returns a new instance which can be used to issue a
|
// NewGetCFilterCmd returns a new instance which can be used to issue a
|
||||||
// getcfilter JSON-RPC command.
|
// getcfilter JSON-RPC command.
|
||||||
func NewGetCFilterCmd(hash string) *GetCFilterCmd {
|
func NewGetCFilterCmd(hash string, extended bool) *GetCFilterCmd {
|
||||||
return &GetCFilterCmd{
|
return &GetCFilterCmd{
|
||||||
Hash: hash,
|
Hash: hash,
|
||||||
|
Extended: extended,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -320,12 +320,12 @@ func TestChainSvrCmds(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "getcfilter",
|
name: "getcfilter",
|
||||||
newCmd: func() (interface{}, error) {
|
newCmd: func() (interface{}, error) {
|
||||||
return btcjson.NewCmd("getcfilter", "123")
|
return btcjson.NewCmd("getcfilter", "123", false)
|
||||||
},
|
},
|
||||||
staticCmd: func() interface{} {
|
staticCmd: func() interface{} {
|
||||||
return btcjson.NewGetCFilterCmd("123")
|
return btcjson.NewGetCFilterCmd("123", false)
|
||||||
},
|
},
|
||||||
marshalled: `{"jsonrpc":"1.0","method":"getcfilter","params":["123"],"id":1}`,
|
marshalled: `{"jsonrpc":"1.0","method":"getcfilter","params":["123",false],"id":1}`,
|
||||||
unmarshalled: &btcjson.GetCFilterCmd{
|
unmarshalled: &btcjson.GetCFilterCmd{
|
||||||
Hash: "123",
|
Hash: "123",
|
||||||
},
|
},
|
||||||
|
|
|
@ -1284,9 +1284,6 @@ func (p *Peer) maybeAddDeadline(pendingResponses map[string]time.Time, msgCmd st
|
||||||
// headers.
|
// headers.
|
||||||
deadline = time.Now().Add(stallResponseTimeout * 3)
|
deadline = time.Now().Add(stallResponseTimeout * 3)
|
||||||
pendingResponses[wire.CmdHeaders] = deadline
|
pendingResponses[wire.CmdHeaders] = deadline
|
||||||
|
|
||||||
// XXX pedro: we may need to handle OnCFilter here depending on the
|
|
||||||
// protocol behaviour defined.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2154,7 +2154,7 @@ func handleGetCFilter(s *rpcServer, cmd interface{}, closeChan <-chan struct{})
|
||||||
return nil, rpcDecodeHexError(c.Hash)
|
return nil, rpcDecodeHexError(c.Hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
filterBytes, err := s.server.cfIndex.FilterByBlockHash(hash)
|
filterBytes, err := s.server.cfIndex.FilterByBlockHash(hash, c.Extended)
|
||||||
if len(filterBytes) > 0 {
|
if len(filterBytes) > 0 {
|
||||||
rpcsLog.Debugf("Found committed filter for %v", hash)
|
rpcsLog.Debugf("Found committed filter for %v", hash)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -746,7 +746,8 @@ func (sp *serverPeer) OnGetCFilter(_ *peer.Peer, msg *wire.MsgGetCFilter) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
filterBytes, err := sp.server.cfIndex.FilterByBlockHash(&msg.BlockHash)
|
filterBytes, err := sp.server.cfIndex.FilterByBlockHash(&msg.BlockHash,
|
||||||
|
msg.Extended)
|
||||||
|
|
||||||
if len(filterBytes) > 0 {
|
if len(filterBytes) > 0 {
|
||||||
peerLog.Infof("Obtained CB filter for %v", msg.BlockHash)
|
peerLog.Infof("Obtained CB filter for %v", msg.BlockHash)
|
||||||
|
|
|
@ -13,16 +13,25 @@ import (
|
||||||
type MsgGetCFilter struct {
|
type MsgGetCFilter struct {
|
||||||
ProtocolVersion uint32
|
ProtocolVersion uint32
|
||||||
BlockHash chainhash.Hash
|
BlockHash chainhash.Hash
|
||||||
|
Extended bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *MsgGetCFilter) BtcDecode(r io.Reader, pver uint32) error {
|
func (msg *MsgGetCFilter) BtcDecode(r io.Reader, pver uint32) error {
|
||||||
return readElement(r, &msg.BlockHash)
|
err := readElement(r, &msg.BlockHash)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return readElement(r, &msg.Extended)
|
||||||
}
|
}
|
||||||
|
|
||||||
// BtcEncode encodes the receiver to w using the bitcoin protocol encoding.
|
// BtcEncode encodes the receiver to w using the bitcoin protocol encoding.
|
||||||
// This is part of the Message interface implementation.
|
// This is part of the Message interface implementation.
|
||||||
func (msg *MsgGetCFilter) BtcEncode(w io.Writer, pver uint32) error {
|
func (msg *MsgGetCFilter) BtcEncode(w io.Writer, pver uint32) error {
|
||||||
return writeElement(w, &msg.BlockHash)
|
err := writeElement(w, &msg.BlockHash)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return writeElement(w, &msg.Extended)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command returns the protocol command string for the message. This is part
|
// Command returns the protocol command string for the message. This is part
|
||||||
|
@ -34,16 +43,17 @@ func (msg *MsgGetCFilter) Command() string {
|
||||||
// MaxPayloadLength returns the maximum length the payload can be for the
|
// MaxPayloadLength returns the maximum length the payload can be for the
|
||||||
// receiver. This is part of the Message interface implementation.
|
// receiver. This is part of the Message interface implementation.
|
||||||
func (msg *MsgGetCFilter) MaxPayloadLength(pver uint32) uint32 {
|
func (msg *MsgGetCFilter) MaxPayloadLength(pver uint32) uint32 {
|
||||||
// Protocol version 4 bytes + block hash.
|
// Protocol version 4 bytes + block hash + Extended flag.
|
||||||
return 4 + chainhash.HashSize
|
return 4 + chainhash.HashSize + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMsgGetCFilter returns a new bitcoin getblocks message that conforms to
|
// NewMsgGetCFilter returns a new bitcoin getblocks message that conforms to
|
||||||
// the Message interface using the passed parameters and defaults for the
|
// the Message interface using the passed parameters and defaults for the
|
||||||
// remaining fields.
|
// remaining fields.
|
||||||
func NewMsgGetCFilter(blockHash *chainhash.Hash) *MsgGetCFilter {
|
func NewMsgGetCFilter(blockHash *chainhash.Hash, extended bool) *MsgGetCFilter {
|
||||||
return &MsgGetCFilter{
|
return &MsgGetCFilter{
|
||||||
ProtocolVersion: ProtocolVersion,
|
ProtocolVersion: ProtocolVersion,
|
||||||
BlockHash: *blockHash,
|
BlockHash: *blockHash,
|
||||||
|
Extended: extended,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue