Replace json hex strings with types.Hash and types.Bytes on monero rpc
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
DataHoarder 2024-04-07 20:19:12 +02:00
parent 1f33aeccc5
commit 142a21861e
Signed by: DataHoarder
SSH key fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk
9 changed files with 171 additions and 203 deletions

View file

@ -10,7 +10,6 @@ import (
"git.gammaspectra.live/P2Pool/consensus/v3/types" "git.gammaspectra.live/P2Pool/consensus/v3/types"
"git.gammaspectra.live/P2Pool/consensus/v3/utils" "git.gammaspectra.live/P2Pool/consensus/v3/utils"
"github.com/floatdrop/lru" "github.com/floatdrop/lru"
fasthex "github.com/tmthrgd/go-hex"
"sync" "sync"
"sync/atomic" "sync/atomic"
"time" "time"
@ -105,14 +104,10 @@ func (c *Client) GetTransactions(txIds ...types.Hash) (data [][]byte, jsonTx []*
return data, jsonTx, nil return data, jsonTx, nil
} }
<-c.throttler <-c.throttler
hs := make([]string, 0, len(txIds)) if result, err := c.d.GetTransactions(context.Background(), txIds); err != nil {
for _, h := range txIds {
hs = append(hs, h.String())
}
if result, err := c.d.GetTransactions(context.Background(), hs); err != nil {
return nil, nil, err return nil, nil, err
} else { } else {
if len(result.Txs) != len(hs) { if len(result.Txs) != len(txIds) {
return nil, nil, errors.New("invalid transaction count") return nil, nil, errors.New("invalid transaction count")
} }
@ -123,11 +118,7 @@ func (c *Client) GetTransactions(txIds ...types.Hash) (data [][]byte, jsonTx []*
} }
for _, tx := range result.Txs { for _, tx := range result.Txs {
if buf, err := fasthex.DecodeString(tx.PrunedAsHex); err != nil { data = append(data, tx.PrunedAsHex)
return nil, nil, err
} else {
data = append(data, buf)
}
} }
} }
@ -137,29 +128,25 @@ func (c *Client) GetTransactions(txIds ...types.Hash) (data [][]byte, jsonTx []*
func (c *Client) GetCoinbaseTransaction(txId types.Hash) (*transaction.CoinbaseTransaction, error) { func (c *Client) GetCoinbaseTransaction(txId types.Hash) (*transaction.CoinbaseTransaction, error) {
if tx := c.coinbaseTransactionCache.Get(txId); tx == nil { if tx := c.coinbaseTransactionCache.Get(txId); tx == nil {
<-c.throttler <-c.throttler
if result, err := c.d.GetTransactions(context.Background(), []string{txId.String()}); err != nil { if result, err := c.d.GetTransactions(context.Background(), []types.Hash{txId}); err != nil {
return nil, err return nil, err
} else { } else {
if len(result.Txs) != 1 { if len(result.Txs) != 1 {
return nil, errors.New("invalid transaction count") return nil, errors.New("invalid transaction count")
} }
if buf, err := fasthex.DecodeString(result.Txs[0].PrunedAsHex); err != nil { tx := &transaction.CoinbaseTransaction{}
if err = tx.UnmarshalBinary(result.Txs[0].PrunedAsHex); err != nil {
return nil, err return nil, err
} else {
tx := &transaction.CoinbaseTransaction{}
if err = tx.UnmarshalBinary(buf); err != nil {
return nil, err
}
if tx.CalculateId() != txId {
return nil, fmt.Errorf("expected %s, got %s", txId.String(), tx.CalculateId().String())
}
c.coinbaseTransactionCache.Set(txId, tx)
return tx, nil
} }
if tx.CalculateId() != txId {
return nil, fmt.Errorf("expected %s, got %s", txId.String(), tx.CalculateId().String())
}
c.coinbaseTransactionCache.Set(txId, tx)
return tx, nil
} }
} else { } else {
return *tx, nil return *tx, nil
@ -182,13 +169,7 @@ type TransactionInput struct {
func (c *Client) GetTransactionInputs(ctx context.Context, hashes ...types.Hash) ([]TransactionInputResult, error) { func (c *Client) GetTransactionInputs(ctx context.Context, hashes ...types.Hash) ([]TransactionInputResult, error) {
<-c.throttler <-c.throttler
if result, err := c.d.GetTransactions(ctx, func() []string { if result, err := c.d.GetTransactions(ctx, hashes); err != nil {
result := make([]string, 0, len(hashes))
for _, h := range hashes {
result = append(result, h.String())
}
return result
}()); err != nil {
return nil, err return nil, err
} else { } else {
if len(result.Txs) != len(hashes) { if len(result.Txs) != len(hashes) {
@ -208,7 +189,7 @@ func (c *Client) GetTransactionInputs(ctx context.Context, hashes ...types.Hash)
s[ix].Inputs = make([]TransactionInput, len(tx.Vin)) s[ix].Inputs = make([]TransactionInput, len(tx.Vin))
for i, input := range tx.Vin { for i, input := range tx.Vin {
s[ix].Inputs[i].Amount = uint64(input.Key.Amount) s[ix].Inputs[i].Amount = uint64(input.Key.Amount)
s[ix].Inputs[i].KeyImage, _ = types.HashFromString(input.Key.KImage) s[ix].Inputs[i].KeyImage = input.Key.KImage
s[ix].Inputs[i].KeyOffsets = make([]uint64, len(input.Key.KeyOffsets)) s[ix].Inputs[i].KeyOffsets = make([]uint64, len(input.Key.KeyOffsets))
for j, o := range input.Key.KeyOffsets { for j, o := range input.Key.KeyOffsets {
s[ix].Inputs[i].KeyOffsets[j] = uint64(o) s[ix].Inputs[i].KeyOffsets[j] = uint64(o)
@ -237,7 +218,7 @@ type Output struct {
func (c *Client) GetOutputIndexes(id types.Hash) (indexes []uint64, err error) { func (c *Client) GetOutputIndexes(id types.Hash) (indexes []uint64, err error) {
<-c.throttler <-c.throttler
return c.d.GetOIndexes(context.Background(), id.String()) return c.d.GetOIndexes(context.Background(), id)
} }
func (c *Client) GetOuts(inputs ...uint64) ([]Output, error) { func (c *Client) GetOuts(inputs ...uint64) ([]Output, error) {
@ -261,9 +242,9 @@ func (c *Client) GetOuts(inputs ...uint64) ([]Output, error) {
o := &result.Outs[i] o := &result.Outs[i]
s[i].GlobalOutputIndex = inputs[i] s[i].GlobalOutputIndex = inputs[i]
s[i].Height = o.Height s[i].Height = o.Height
s[i].Key, _ = types.HashFromString(o.Key) s[i].Key = o.Key
s[i].Mask, _ = types.HashFromString(o.Mask) s[i].Mask = o.Mask
s[i].TransactionId, _ = types.HashFromString(o.Txid) s[i].TransactionId = o.Txid
s[i].Unlocked = o.Unlocked s[i].Unlocked = o.Unlocked
} }
@ -300,7 +281,7 @@ func (c *Client) GetInfo() (*daemon.GetInfoResult, error) {
func (c *Client) GetBlockHeaderByHash(hash types.Hash, ctx context.Context) (*daemon.BlockHeader, error) { func (c *Client) GetBlockHeaderByHash(hash types.Hash, ctx context.Context) (*daemon.BlockHeader, error) {
<-c.throttler <-c.throttler
if result, err := c.d.GetBlockHeaderByHash(ctx, []string{hash.String()}); err != nil { if result, err := c.d.GetBlockHeaderByHash(ctx, []types.Hash{hash}); err != nil {
return nil, err return nil, err
} else if result != nil && len(result.BlockHeaders) > 0 { } else if result != nil && len(result.BlockHeaders) > 0 {
return &result.BlockHeaders[0], nil return &result.BlockHeaders[0], nil
@ -312,7 +293,7 @@ func (c *Client) GetBlockHeaderByHash(hash types.Hash, ctx context.Context) (*da
func (c *Client) GetBlock(hash types.Hash, ctx context.Context) (*daemon.GetBlockResult, error) { func (c *Client) GetBlock(hash types.Hash, ctx context.Context) (*daemon.GetBlockResult, error) {
<-c.throttler <-c.throttler
if result, err := c.d.GetBlock(ctx, daemon.GetBlockRequestParameters{ if result, err := c.d.GetBlock(ctx, daemon.GetBlockRequestParameters{
Hash: hash.String(), Hash: hash,
}); err != nil { }); err != nil {
return nil, err return nil, err
} else { } else {

View file

@ -5,7 +5,7 @@ import (
"context" "context"
"errors" "errors"
"git.gammaspectra.live/P2Pool/consensus/v3/monero/client/levin" "git.gammaspectra.live/P2Pool/consensus/v3/monero/client/levin"
fasthex "github.com/tmthrgd/go-hex" "git.gammaspectra.live/P2Pool/consensus/v3/types"
"io" "io"
) )
@ -14,18 +14,13 @@ const (
) )
func (c *Client) GetOIndexes( func (c *Client) GetOIndexes(
ctx context.Context, txid string, ctx context.Context, txid types.Hash,
) (indexes []uint64, finalError error) { ) (indexes []uint64, finalError error) {
binaryTxId, err := fasthex.DecodeString(txid)
if err != nil {
return nil, err
}
storage := levin.PortableStorage{Entries: levin.Entries{ storage := levin.PortableStorage{Entries: levin.Entries{
levin.Entry{ levin.Entry{
Name: "txid", Name: "txid",
Serializable: levin.BoostString(binaryTxId), Serializable: levin.BoostString(txid[:]),
}, },
}} }}

View file

@ -3,8 +3,8 @@ package daemon
import ( import (
"context" "context"
"fmt" "fmt"
"git.gammaspectra.live/P2Pool/consensus/v3/types"
"git.gammaspectra.live/P2Pool/consensus/v3/utils" "git.gammaspectra.live/P2Pool/consensus/v3/utils"
fasthex "github.com/tmthrgd/go-hex"
) )
const ( const (
@ -189,20 +189,20 @@ func (c *Client) GetBlockCount(
func (c *Client) OnGetBlockHash( func (c *Client) OnGetBlockHash(
ctx context.Context, height uint64, ctx context.Context, height uint64,
) (string, error) { ) (types.Hash, error) {
resp := "" resp := ""
params := []uint64{height} params := []uint64{height}
err := c.JSONRPC(ctx, methodOnGetBlockHash, params, &resp) err := c.JSONRPC(ctx, methodOnGetBlockHash, params, &resp)
if err != nil { if err != nil {
return "", fmt.Errorf("jsonrpc: %w", err) return types.ZeroHash, fmt.Errorf("jsonrpc: %w", err)
} }
return resp, nil return types.HashFromString(resp)
} }
func (c *Client) RelayTx( func (c *Client) RelayTx(
ctx context.Context, txns []string, ctx context.Context, txns []types.Hash,
) (*RelayTxResult, error) { ) (*RelayTxResult, error) {
resp := &RelayTxResult{} resp := &RelayTxResult{}
params := map[string]interface{}{ params := map[string]interface{}{
@ -246,15 +246,10 @@ func (c *Client) GetMinerData(ctx context.Context) (*GetMinerDataResult, error)
return resp, nil return resp, nil
} }
func (c *Client) SubmitBlock(ctx context.Context, blobs ...[]byte) (*SubmitBlockResult, error) { func (c *Client) SubmitBlock(ctx context.Context, blobs ...types.Bytes) (*SubmitBlockResult, error) {
resp := &SubmitBlockResult{} resp := &SubmitBlockResult{}
params := make([]string, 0, len(blobs)) err := c.JSONRPC(ctx, methodSubmitBlock, blobs, resp)
for _, blob := range blobs {
params = append(params, fasthex.EncodeToString(blob))
}
err := c.JSONRPC(ctx, methodSubmitBlock, params, resp)
if err != nil { if err != nil {
return nil, fmt.Errorf("jsonrpc: %w", err) return nil, fmt.Errorf("jsonrpc: %w", err)
} }
@ -367,7 +362,7 @@ func (c *Client) GetBlockHeaderByHeight(
// GetBlockHeaderByHash retrieves block header information for either one or // GetBlockHeaderByHash retrieves block header information for either one or
// multiple blocks. // multiple blocks.
func (c *Client) GetBlockHeaderByHash( func (c *Client) GetBlockHeaderByHash(
ctx context.Context, hashes []string, ctx context.Context, hashes []types.Hash,
) (*GetBlockHeaderByHashResult, error) { ) (*GetBlockHeaderByHashResult, error) {
resp := &GetBlockHeaderByHashResult{} resp := &GetBlockHeaderByHashResult{}
params := map[string]interface{}{ params := map[string]interface{}{
@ -385,8 +380,8 @@ func (c *Client) GetBlockHeaderByHash(
// GetBlockRequestParameters represents the set of possible parameters that can // GetBlockRequestParameters represents the set of possible parameters that can
// be used for submitting a call to the `get_block` jsonrpc method. // be used for submitting a call to the `get_block` jsonrpc method.
type GetBlockRequestParameters struct { type GetBlockRequestParameters struct {
Height uint64 `json:"height,omitempty"` Height uint64 `json:"height,omitempty"`
Hash string `json:"hash,omitempty"` Hash types.Hash `json:"hash,omitempty"`
} }
// GetBlock fetches full block information from a block at a particular hash OR // GetBlock fetches full block information from a block at a particular hash OR

View file

@ -3,6 +3,7 @@ package daemon
import ( import (
"context" "context"
"fmt" "fmt"
"git.gammaspectra.live/P2Pool/consensus/v3/types"
"git.gammaspectra.live/P2Pool/consensus/v3/utils" "git.gammaspectra.live/P2Pool/consensus/v3/utils"
) )
@ -242,7 +243,7 @@ func (r *GetTransactionsResult) GetTransactions() ([]*TransactionJSON, error) {
} }
func (c *Client) GetTransactions( func (c *Client) GetTransactions(
ctx context.Context, txns []string, ctx context.Context, txns []types.Hash,
) (*GetTransactionsResult, error) { ) (*GetTransactionsResult, error) {
resp := &GetTransactionsResult{} resp := &GetTransactionsResult{}
params := map[string]interface{}{ params := map[string]interface{}{

View file

@ -1,5 +1,10 @@
package daemon package daemon
import (
"git.gammaspectra.live/P2Pool/consensus/v3/p2pool/mempool"
"git.gammaspectra.live/P2Pool/consensus/v3/types"
)
// RPCResultFooter contains the set of fields that every RPC result message // RPCResultFooter contains the set of fields that every RPC result message
// will contain. // will contain.
type RPCResultFooter struct { type RPCResultFooter struct {
@ -33,11 +38,11 @@ type GetAlternateChainsResult struct {
// BlockHash is the hash of the first diverging block of this // BlockHash is the hash of the first diverging block of this
// alternative chain. // alternative chain.
// //
BlockHash string `json:"block_hash"` BlockHash types.Hash `json:"block_hash"`
// BlockHashes TODO // BlockHashes TODO
// //
BlockHashes []string `json:"block_hashes"` BlockHashes []types.Hash `json:"block_hashes"`
// Difficulty is the cumulative difficulty of all blocks in the // Difficulty is the cumulative difficulty of all blocks in the
// alternative chain. // alternative chain.
@ -61,7 +66,7 @@ type GetAlternateChainsResult struct {
// MainChainParentBlock TODO // MainChainParentBlock TODO
// //
MainChainParentBlock string `json:"main_chain_parent_block"` MainChainParentBlock types.Hash `json:"main_chain_parent_block"`
// WideDifficulty is the network difficulty as a hexadecimal // WideDifficulty is the network difficulty as a hexadecimal
// string representing a 128-bit number. // string representing a 128-bit number.
@ -194,44 +199,44 @@ type GetFeeEstimateResult struct {
// GetInfoResult is the result of a call to the GetInfo RPC method. // GetInfoResult is the result of a call to the GetInfo RPC method.
type GetInfoResult struct { type GetInfoResult struct {
AdjustedTime uint64 `json:"adjusted_time"` AdjustedTime uint64 `json:"adjusted_time"`
AltBlocksCount int `json:"alt_blocks_count"` AltBlocksCount int `json:"alt_blocks_count"`
BlockSizeLimit uint64 `json:"block_size_limit"` BlockSizeLimit uint64 `json:"block_size_limit"`
BlockSizeMedian uint64 `json:"block_size_median"` BlockSizeMedian uint64 `json:"block_size_median"`
BlockWeightLimit uint64 `json:"block_weight_limit"` BlockWeightLimit uint64 `json:"block_weight_limit"`
BlockWeightMedian uint64 `json:"block_weight_median"` BlockWeightMedian uint64 `json:"block_weight_median"`
BootstrapDaemonAddress string `json:"bootstrap_daemon_address"` BootstrapDaemonAddress string `json:"bootstrap_daemon_address"`
BusySyncing bool `json:"busy_syncing"` BusySyncing bool `json:"busy_syncing"`
CumulativeDifficulty int64 `json:"cumulative_difficulty"` CumulativeDifficulty int64 `json:"cumulative_difficulty"`
CumulativeDifficultyTop64 uint64 `json:"cumulative_difficulty_top64"` CumulativeDifficultyTop64 uint64 `json:"cumulative_difficulty_top64"`
DatabaseSize uint64 `json:"database_size"` DatabaseSize uint64 `json:"database_size"`
Difficulty uint64 `json:"difficulty"` Difficulty uint64 `json:"difficulty"`
DifficultyTop64 uint64 `json:"difficulty_top64"` DifficultyTop64 uint64 `json:"difficulty_top64"`
FreeSpace uint64 `json:"free_space"` FreeSpace uint64 `json:"free_space"`
GreyPeerlistSize uint `json:"grey_peerlist_size"` GreyPeerlistSize uint `json:"grey_peerlist_size"`
Height uint64 `json:"height"` Height uint64 `json:"height"`
HeightWithoutBootstrap uint64 `json:"height_without_bootstrap"` HeightWithoutBootstrap uint64 `json:"height_without_bootstrap"`
IncomingConnectionsCount uint `json:"incoming_connections_count"` IncomingConnectionsCount uint `json:"incoming_connections_count"`
Mainnet bool `json:"mainnet"` Mainnet bool `json:"mainnet"`
Nettype string `json:"nettype"` Nettype string `json:"nettype"`
Offline bool `json:"offline"` Offline bool `json:"offline"`
OutgoingConnectionsCount uint `json:"outgoing_connections_count"` OutgoingConnectionsCount uint `json:"outgoing_connections_count"`
RPCConnectionsCount uint `json:"rpc_connections_count"` RPCConnectionsCount uint `json:"rpc_connections_count"`
Stagenet bool `json:"stagenet"` Stagenet bool `json:"stagenet"`
StartTime uint64 `json:"start_time"` StartTime uint64 `json:"start_time"`
Synchronized bool `json:"synchronized"` Synchronized bool `json:"synchronized"`
Target uint64 `json:"target"` Target uint64 `json:"target"`
TargetHeight uint64 `json:"target_height"` TargetHeight uint64 `json:"target_height"`
Testnet bool `json:"testnet"` Testnet bool `json:"testnet"`
TopBlockHash string `json:"top_block_hash"` TopBlockHash types.Hash `json:"top_block_hash"`
TxCount uint64 `json:"tx_count"` TxCount uint64 `json:"tx_count"`
TxPoolSize uint64 `json:"tx_pool_size"` TxPoolSize uint64 `json:"tx_pool_size"`
UpdateAvailable bool `json:"update_available"` UpdateAvailable bool `json:"update_available"`
Version string `json:"version"` Version string `json:"version"`
WasBootstrapEverUsed bool `json:"was_bootstrap_ever_used"` WasBootstrapEverUsed bool `json:"was_bootstrap_ever_used"`
WhitePeerlistSize uint `json:"white_peerlist_size"` WhitePeerlistSize uint `json:"white_peerlist_size"`
WideCumulativeDifficulty string `json:"wide_cumulative_difficulty"` WideCumulativeDifficulty string `json:"wide_cumulative_difficulty"`
WideDifficulty string `json:"wide_difficulty"` WideDifficulty string `json:"wide_difficulty"`
RPCResultFooter `json:",inline"` RPCResultFooter `json:",inline"`
} }
@ -241,11 +246,11 @@ type GetInfoResult struct {
type GetBlockTemplateResult struct { type GetBlockTemplateResult struct {
// BlockhashingBlob is the blob on which to try to find a valid nonce. // BlockhashingBlob is the blob on which to try to find a valid nonce.
// //
BlockhashingBlob string `json:"blockhashing_blob"` BlockhashingBlob types.Bytes `json:"blockhashing_blob"`
// BlocktemplateBlob is the blob on which to try to mine a new block. // BlocktemplateBlob is the blob on which to try to mine a new block.
// //
BlocktemplateBlob string `json:"blocktemplate_blob"` BlocktemplateBlob types.Bytes `json:"blocktemplate_blob"`
// Difficulty is the difficulty of the next block. // Difficulty is the difficulty of the next block.
Difficulty int64 `json:"difficulty"` Difficulty int64 `json:"difficulty"`
@ -262,7 +267,7 @@ type GetBlockTemplateResult struct {
// PrevHash is the hash of the most recent block on which to mine the // PrevHash is the hash of the most recent block on which to mine the
// next block. // next block.
// //
PrevHash string `json:"prev_hash"` PrevHash types.Hash `json:"prev_hash"`
// ReservedOffset TODO // ReservedOffset TODO
// //
@ -274,20 +279,15 @@ type GetBlockTemplateResult struct {
// GetMinerDataResult is the result of a call to the GetMinerData RPC // GetMinerDataResult is the result of a call to the GetMinerData RPC
// method. // method.
type GetMinerDataResult struct { type GetMinerDataResult struct {
MajorVersion uint8 `json:"major_version"` MajorVersion uint8 `json:"major_version"`
Height uint64 `json:"height"` Height uint64 `json:"height"`
PrevId string `json:"prev_id"` PrevId types.Hash `json:"prev_id"`
SeedHash string `json:"seed_hash"` SeedHash types.Hash `json:"seed_hash"`
Difficulty string `json:"difficulty"` Difficulty types.Difficulty `json:"difficulty"`
MedianWeight uint64 `json:"median_weight"` MedianWeight uint64 `json:"median_weight"`
AlreadyGeneratedCoins uint64 `json:"already_generated_coins"` AlreadyGeneratedCoins uint64 `json:"already_generated_coins"`
MedianTimestamp uint64 `json:"median_timestamp"` MedianTimestamp uint64 `json:"median_timestamp"`
TxBacklog []struct { TxBacklog mempool.Mempool `json:"tx_backlog"`
Id string `json:"id"`
BlobSize uint64 `json:"blob_size"`
Weight uint64 `json:"weight"`
Fee uint64 `json:"fee"`
} `json:"tx_backlog"`
} }
// SubmitBlockResult is the result of a call to the SubmitBlock RPC // SubmitBlockResult is the result of a call to the SubmitBlock RPC
@ -352,11 +352,11 @@ type GetConnectionsResult struct {
type GetOutsResult struct { type GetOutsResult struct {
Outs []struct { Outs []struct {
Height uint64 `json:"height"` Height uint64 `json:"height"`
Key string `json:"key"` Key types.Hash `json:"key"`
Mask string `json:"mask"` Mask types.Hash `json:"mask"`
Txid string `json:"txid"` Txid types.Hash `json:"txid"`
Unlocked bool `json:"unlocked"` Unlocked bool `json:"unlocked"`
} `json:"outs"` } `json:"outs"`
RPCResultFooter `json:",inline"` RPCResultFooter `json:",inline"`
@ -364,8 +364,8 @@ type GetOutsResult struct {
// GetHeightResult is the result of a call to the GetHeight RPC method. // GetHeightResult is the result of a call to the GetHeight RPC method.
type GetHeightResult struct { type GetHeightResult struct {
Hash string `json:"hash"` Hash types.Hash `json:"hash"`
Height uint64 `json:"height"` Height uint64 `json:"height"`
RPCResultFooter `json:",inline"` RPCResultFooter `json:",inline"`
} }
@ -393,8 +393,8 @@ type GetPublicNodesResult struct {
// GenerateBlocksResult is the result of a call to the GenerateBlocks RPC // GenerateBlocksResult is the result of a call to the GenerateBlocks RPC
// method. // method.
type GenerateBlocksResult struct { type GenerateBlocksResult struct {
Blocks []string `json:"blocks"` Blocks []types.Hash `json:"blocks"`
Height int `json:"height"` Height int `json:"height"`
RPCResultFooter `json:",inline"` RPCResultFooter `json:",inline"`
} }
@ -460,7 +460,7 @@ type BlockHeader struct {
// Hash is the hash of this block. // Hash is the hash of this block.
// //
Hash string `json:"hash"` Hash types.Hash `json:"hash"`
// Height is the number of blocks preceding this block on the // Height is the number of blocks preceding this block on the
// blockchain. // blockchain.
@ -478,7 +478,7 @@ type BlockHeader struct {
// MinerTxHash TODO // MinerTxHash TODO
// //
MinerTxHash string `json:"miner_tx_hash"` MinerTxHash types.Hash `json:"miner_tx_hash"`
// MinorVersion is the minor version of the monero protocol at // MinorVersion is the minor version of the monero protocol at
// this block height. // this block height.
@ -502,12 +502,12 @@ type BlockHeader struct {
// PowHash TODO // PowHash TODO
// //
PowHash string `json:"pow_hash"` PowHash types.Hash `json:"pow_hash"`
// PrevHash is the hash of the block immediately preceding this // PrevHash is the hash of the block immediately preceding this
// block in the chain. // block in the chain.
// //
PrevHash string `json:"prev_hash"` PrevHash types.Hash `json:"prev_hash,omitempty"`
// Reward the amount of new atomic-units generated in this // Reward the amount of new atomic-units generated in this
// block and rewarded to the miner (1XMR = 1e12 atomic units). // block and rewarded to the miner (1XMR = 1e12 atomic units).
@ -535,7 +535,7 @@ type BlockHeader struct {
type GetBlockResult struct { type GetBlockResult struct {
// Blob is a hexadecimal representation of the block. // Blob is a hexadecimal representation of the block.
// //
Blob string `json:"blob"` Blob types.Bytes `json:"blob"`
// BlockHeader contains the details from the block header. // BlockHeader contains the details from the block header.
// //
@ -548,7 +548,7 @@ type GetBlockResult struct {
// MinerTxHash is the hash of the coinbase transaction // MinerTxHash is the hash of the coinbase transaction
// //
MinerTxHash string `json:"miner_tx_hash"` MinerTxHash types.Hash `json:"miner_tx_hash"`
RPCResultFooter `json:",inline"` RPCResultFooter `json:",inline"`
} }
@ -569,7 +569,7 @@ type GetBlockResultJSON struct {
// PrevID (same as `block_hash` in the block header) // PrevID (same as `block_hash` in the block header)
// //
PrevID string `json:"prev_id"` PrevID types.Hash `json:"prev_id"`
// Nonce (same as in the block header) // Nonce (same as in the block header)
// //
@ -600,7 +600,7 @@ type GetBlockResultJSON struct {
Vout []struct { Vout []struct {
Amount uint64 `json:"amount"` Amount uint64 `json:"amount"`
Target struct { Target struct {
Key string `json:"key"` Key types.Hash `json:"key"`
} `json:"target"` } `json:"target"`
} `json:"vout"` } `json:"vout"`
// Extra (aka the transaction id) can be used to include any // Extra (aka the transaction id) can be used to include any
@ -620,7 +620,7 @@ type GetBlockResultJSON struct {
// TxHashes is the list of hashes of non-coinbase transactions in the // TxHashes is the list of hashes of non-coinbase transactions in the
// block. // block.
// //
TxHashes []string `json:"tx_hashes"` TxHashes []types.Hash `json:"tx_hashes"`
} }
func (c *GetBlockResultJSON) MinerOutputs() uint64 { func (c *GetBlockResultJSON) MinerOutputs() uint64 {
@ -637,13 +637,13 @@ func (c *GetBlockResultJSON) MinerOutputs() uint64 {
type SyncInfoResult struct { type SyncInfoResult struct {
Credits uint64 `json:"credits"` Credits uint64 `json:"credits"`
Height uint64 `json:"height"` Height uint64 `json:"height"`
NextNeededPruningSeed uint64 `json:"next_needed_pruning_seed"` NextNeededPruningSeed uint64 `json:"next_needed_pruning_seed"`
Overview string `json:"overview"` Overview string `json:"overview"`
Status string `json:"status"` Status string `json:"status"`
TargetHeight uint64 `json:"target_height"` TargetHeight uint64 `json:"target_height"`
TopHash string `json:"top_hash"` TopHash types.Hash `json:"top_hash"`
Untrusted bool `json:"untrusted"` Untrusted bool `json:"untrusted"`
Peers []struct { Peers []struct {
Info struct { Info struct {
Address string `json:"address"` Address string `json:"address"`
@ -756,25 +756,25 @@ type GetTransactionPoolStatsResult struct {
} }
type GetTransactionsResultTransaction struct { type GetTransactionsResultTransaction struct {
AsHex string `json:"as_hex"` AsHex types.Bytes `json:"as_hex"`
AsJSON string `json:"as_json"` AsJSON string `json:"as_json"`
BlockHeight uint64 `json:"block_height"` BlockHeight uint64 `json:"block_height"`
BlockTimestamp int64 `json:"block_timestamp"` BlockTimestamp int64 `json:"block_timestamp"`
DoubleSpendSeen bool `json:"double_spend_seen"` DoubleSpendSeen bool `json:"double_spend_seen"`
InPool bool `json:"in_pool"` InPool bool `json:"in_pool"`
OutputIndices []int `json:"output_indices"` OutputIndices []int `json:"output_indices"`
PrunableAsHex string `json:"prunable_as_hex"` PrunableAsHex types.Bytes `json:"prunable_as_hex"`
PrunableHash string `json:"prunable_hash"` PrunableHash types.Hash `json:"prunable_hash"`
PrunedAsHex string `json:"pruned_as_hex"` PrunedAsHex types.Bytes `json:"pruned_as_hex"`
TxHash string `json:"tx_hash"` TxHash types.Hash `json:"tx_hash"`
} }
type GetTransactionsResult struct { type GetTransactionsResult struct {
Credits int `json:"credits"` Credits int `json:"credits"`
Status string `json:"status"` Status string `json:"status"`
TopHash string `json:"top_hash"` TopHash types.Hash `json:"top_hash"`
Txs []GetTransactionsResultTransaction `json:"txs"` Txs []GetTransactionsResultTransaction `json:"txs"`
TxsAsHex []string `json:"txs_as_hex"` TxsAsHex []types.Bytes `json:"txs_as_hex"`
Untrusted bool `json:"untrusted"` Untrusted bool `json:"untrusted"`
} }
@ -783,15 +783,15 @@ type TransactionJSON struct {
UnlockTime int `json:"unlock_time"` UnlockTime int `json:"unlock_time"`
Vin []struct { Vin []struct {
Key struct { Key struct {
Amount int `json:"amount"` Amount int `json:"amount"`
KeyOffsets []uint `json:"key_offsets"` KeyOffsets []uint `json:"key_offsets"`
KImage string `json:"k_image"` KImage types.Hash `json:"k_image"`
} `json:"key"` } `json:"key"`
} `json:"vin"` } `json:"vin"`
Vout []struct { Vout []struct {
Amount uint64 `json:"amount"` Amount uint64 `json:"amount"`
Target struct { Target struct {
Key string `json:"key"` Key types.Hash `json:"key"`
} `json:"target"` } `json:"target"`
} `json:"vout"` } `json:"vout"`
Extra []byte `json:"extra"` Extra []byte `json:"extra"`
@ -840,28 +840,28 @@ type TransactionJSON struct {
type GetTransactionPoolResult struct { type GetTransactionPoolResult struct {
Credits int `json:"credits"` Credits int `json:"credits"`
SpentKeyImages []struct { SpentKeyImages []struct {
IDHash string `json:"id_hash"` IDHash types.Hash `json:"id_hash"`
TxsHashes []string `json:"txs_hashes"` TxsHashes []types.Hash `json:"txs_hashes"`
} `json:"spent_key_images"` } `json:"spent_key_images"`
Status string `json:"status"` Status string `json:"status"`
TopHash string `json:"top_hash"` TopHash types.Hash `json:"top_hash"`
Transactions []struct { Transactions []struct {
BlobSize uint64 `json:"blob_size"` BlobSize uint64 `json:"blob_size"`
DoNotRelay bool `json:"do_not_relay"` DoNotRelay bool `json:"do_not_relay"`
DoubleSpendSeen bool `json:"double_spend_seen"` DoubleSpendSeen bool `json:"double_spend_seen"`
Fee uint64 `json:"fee"` Fee uint64 `json:"fee"`
IDHash string `json:"id_hash"` IDHash types.Hash `json:"id_hash"`
KeptByBlock bool `json:"kept_by_block"` KeptByBlock bool `json:"kept_by_block"`
LastFailedHeight uint64 `json:"last_failed_height"` LastFailedHeight uint64 `json:"last_failed_height"`
LastFailedIDHash string `json:"last_failed_id_hash"` LastFailedIDHash string `json:"last_failed_id_hash"`
LastRelayedTime uint64 `json:"last_relayed_time"` LastRelayedTime uint64 `json:"last_relayed_time"`
MaxUsedBlockHeight uint64 `json:"max_used_block_height"` MaxUsedBlockHeight uint64 `json:"max_used_block_height"`
MaxUsedBlockIDHash string `json:"max_used_block_id_hash"` MaxUsedBlockIDHash string `json:"max_used_block_id_hash"`
ReceiveTime int64 `json:"receive_time"` ReceiveTime int64 `json:"receive_time"`
Relayed bool `json:"relayed"` Relayed bool `json:"relayed"`
TxBlob string `json:"tx_blob"` TxBlob string `json:"tx_blob"`
TxJSON string `json:"tx_json"` TxJSON string `json:"tx_json"`
Weight uint64 `json:"weight"` Weight uint64 `json:"weight"`
} `json:"transactions"` } `json:"transactions"`
Untrusted bool `json:"untrusted"` Untrusted bool `json:"untrusted"`
} }

View file

@ -356,18 +356,16 @@ func (c *MainChain) DownloadBlockHeaders(currentHeight uint64) error {
return fmt.Errorf("couldn't download block headers range for height %d to %d: %s", startHeight, currentHeight-1, err) return fmt.Errorf("couldn't download block headers range for height %d to %d: %s", startHeight, currentHeight-1, err)
} else { } else {
for _, header := range rangeResult.Headers { for _, header := range rangeResult.Headers {
prevHash, _ := types.HashFromString(header.PrevHash)
h, _ := types.HashFromString(header.Hash)
c.HandleMainHeader(&mainblock.Header{ c.HandleMainHeader(&mainblock.Header{
MajorVersion: uint8(header.MajorVersion), MajorVersion: uint8(header.MajorVersion),
MinorVersion: uint8(header.MinorVersion), MinorVersion: uint8(header.MinorVersion),
Timestamp: uint64(header.Timestamp), Timestamp: uint64(header.Timestamp),
PreviousId: prevHash, PreviousId: header.PrevHash,
Height: header.Height, Height: header.Height,
Nonce: uint32(header.Nonce), Nonce: uint32(header.Nonce),
Reward: header.Reward, Reward: header.Reward,
Id: h, Id: header.Hash,
Difficulty: types.DifficultyFrom64(header.Difficulty), Difficulty: types.NewDifficulty(header.Difficulty, header.DifficultyTop64),
}) })
} }
utils.Logf("MainChain", "Downloaded headers for range %d to %d", startHeight, currentHeight-1) utils.Logf("MainChain", "Downloaded headers for range %d to %d", startHeight, currentHeight-1)
@ -457,18 +455,16 @@ func (c *MainChain) getBlockHeader(height uint64) error {
if header, err := c.p2pool.ClientRPC().GetBlockHeaderByHeight(height, c.p2pool.Context()); err != nil { if header, err := c.p2pool.ClientRPC().GetBlockHeaderByHeight(height, c.p2pool.Context()); err != nil {
return fmt.Errorf("couldn't download block header for height %d: %s", height, err) return fmt.Errorf("couldn't download block header for height %d: %s", height, err)
} else { } else {
prevHash, _ := types.HashFromString(header.BlockHeader.PrevHash)
h, _ := types.HashFromString(header.BlockHeader.Hash)
c.HandleMainHeader(&mainblock.Header{ c.HandleMainHeader(&mainblock.Header{
MajorVersion: uint8(header.BlockHeader.MajorVersion), MajorVersion: uint8(header.BlockHeader.MajorVersion),
MinorVersion: uint8(header.BlockHeader.MinorVersion), MinorVersion: uint8(header.BlockHeader.MinorVersion),
Timestamp: uint64(header.BlockHeader.Timestamp), Timestamp: uint64(header.BlockHeader.Timestamp),
PreviousId: prevHash, PreviousId: header.BlockHeader.PrevHash,
Height: header.BlockHeader.Height, Height: header.BlockHeader.Height,
Nonce: uint32(header.BlockHeader.Nonce), Nonce: uint32(header.BlockHeader.Nonce),
Reward: header.BlockHeader.Reward, Reward: header.BlockHeader.Reward,
Id: h, Id: header.BlockHeader.Hash,
Difficulty: types.DifficultyFrom64(header.BlockHeader.Difficulty), Difficulty: types.NewDifficulty(header.BlockHeader.Difficulty, header.BlockHeader.DifficultyTop64),
}) })
} }

View file

@ -63,12 +63,12 @@ func (s *FakeServer) GetMinimalBlockHeaderByHeight(height uint64) *mainblock.Hea
MajorVersion: uint8(h.BlockHeader.MajorVersion), MajorVersion: uint8(h.BlockHeader.MajorVersion),
MinorVersion: uint8(h.BlockHeader.MinorVersion), MinorVersion: uint8(h.BlockHeader.MinorVersion),
Timestamp: uint64(h.BlockHeader.Timestamp), Timestamp: uint64(h.BlockHeader.Timestamp),
PreviousId: types.MustHashFromString(h.BlockHeader.PrevHash), PreviousId: h.BlockHeader.PrevHash,
Height: h.BlockHeader.Height, Height: h.BlockHeader.Height,
Nonce: uint32(h.BlockHeader.Nonce), Nonce: uint32(h.BlockHeader.Nonce),
Reward: h.BlockHeader.Reward, Reward: h.BlockHeader.Reward,
Difficulty: types.DifficultyFrom64(h.BlockHeader.Difficulty), Difficulty: types.NewDifficulty(h.BlockHeader.Difficulty, h.BlockHeader.DifficultyTop64),
Id: types.MustHashFromString(h.BlockHeader.Hash), Id: h.BlockHeader.Hash,
} }
s.headers[height] = header s.headers[height] = header
return header return header

View file

@ -20,7 +20,7 @@ func testPoolBlock(b *PoolBlock, t *testing.T, expectedBufferLength int, majorVe
if h, err := client.GetDefaultClient().GetBlockByHeight(seedHeight, context.Background()); err != nil { if h, err := client.GetDefaultClient().GetBlockByHeight(seedHeight, context.Background()); err != nil {
return types.ZeroHash return types.ZeroHash
} else { } else {
return types.MustHashFromString(h.BlockHeader.Hash) return h.BlockHeader.Hash
} }
}) })
@ -58,7 +58,7 @@ func testPoolBlock(b *PoolBlock, t *testing.T, expectedBufferLength int, majorVe
if h, err := client.GetDefaultClient().GetBlockByHeight(seedHeight, context.Background()); err != nil { if h, err := client.GetDefaultClient().GetBlockByHeight(seedHeight, context.Background()); err != nil {
return types.ZeroHash return types.ZeroHash
} else { } else {
return types.MustHashFromString(h.BlockHeader.Hash) return h.BlockHeader.Hash
} }
}) { }) {
t.Fatal() t.Fatal()

View file

@ -47,9 +47,9 @@ func getMinerData() *p2pooltypes.MinerData {
return &p2pooltypes.MinerData{ return &p2pooltypes.MinerData{
MajorVersion: d.MajorVersion, MajorVersion: d.MajorVersion,
Height: d.Height, Height: d.Height,
PrevId: types.MustHashFromString(d.PrevId), PrevId: d.PrevId,
SeedHash: types.MustHashFromString(d.SeedHash), SeedHash: d.SeedHash,
Difficulty: types.MustDifficultyFromString(d.Difficulty), Difficulty: d.Difficulty,
MedianWeight: d.MedianWeight, MedianWeight: d.MedianWeight,
AlreadyGeneratedCoins: d.AlreadyGeneratedCoins, AlreadyGeneratedCoins: d.AlreadyGeneratedCoins,
MedianTimestamp: d.MedianTimestamp, MedianTimestamp: d.MedianTimestamp,