Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion qkc/cluster/slave/xshard_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/ethereum/go-ethereum/qkc/cluster/conn"
"github.com/ethereum/go-ethereum/qkc/cluster/wire"
"github.com/ethereum/go-ethereum/qkc/serialize"
"github.com/ethereum/go-ethereum/qkc/types"
)

// XshardHandler serves inbound xshard requests, implemented by the business
Expand Down Expand Up @@ -234,7 +235,7 @@ func (x *XshardConn) sendPing(ctx context.Context) ([]byte, []uint32, error) {
req := &wire.PingRequest{
ID: x.localID,
FullShardIDList: x.localFullShardIDList,
RootTip: nil, // TODO: RootTip stays nil until the RootBlock wire type is ported.
RootTip: types.NewRootBlockWithHeader(&types.RootBlockHeader{}),
}
resp, err := x.sendRPC(ctx, byte(wire.ClusterOpPing), req)
if err != nil {
Expand Down
9 changes: 5 additions & 4 deletions qkc/cluster/slave/xshard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/qkc/cluster/wire"
"github.com/ethereum/go-ethereum/qkc/serialize"
"github.com/ethereum/go-ethereum/qkc/types"
)

// ── pool test helpers (white-box, same package) ──────────────────────────────
Expand Down Expand Up @@ -236,7 +237,7 @@ func TestXshardConn_XshardTxListServedByHandler(t *testing.T) {
server.Start()
client.Start()

txList := wire.RawBytes{}
txList := types.CrossShardTransactionList{}
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
if err := client.SendAddXshardTxList(ctx, &wire.AddXshardTxListRequest{
Expand All @@ -259,7 +260,7 @@ func TestXshardConn_BatchAddXshardTxListServedByHandler(t *testing.T) {
server.Start()
client.Start()

txList := wire.RawBytes{}
txList := types.CrossShardTransactionList{}
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
if err := client.SendBatchAddXshardTxList(ctx, &wire.BatchAddXshardTxListRequest{
Expand Down Expand Up @@ -721,7 +722,7 @@ func TestXshardPool_SequentialDialLeavesOneLiveRoute(t *testing.T) {
// retained (inbound) end back to S0 across the kept connection.
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
if err := pool1.Lookup(s0Shards[0])[0].SendAddXshardTxList(ctx, &wire.AddXshardTxListRequest{Branch: s0Shards[0], TxList: &wire.RawBytes{}}); err != nil {
if err := pool1.Lookup(s0Shards[0])[0].SendAddXshardTxList(ctx, &wire.AddXshardTxListRequest{Branch: s0Shards[0], TxList: &types.CrossShardTransactionList{}}); err != nil {
t.Fatalf("round-trip over retained route failed: %v", err)
}
}
Expand Down Expand Up @@ -874,7 +875,7 @@ func TestXshardConn_SendXshardTxListErrorCode(t *testing.T) {

ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
err = client.SendAddXshardTxList(ctx, &wire.AddXshardTxListRequest{Branch: 1, TxList: &wire.RawBytes{}})
err = client.SendAddXshardTxList(ctx, &wire.AddXshardTxListRequest{Branch: 1, TxList: &types.CrossShardTransactionList{}})
if tc.wantErr {
if err == nil {
t.Fatal("expected error for non-zero error_code, got nil")
Expand Down
113 changes: 50 additions & 63 deletions qkc/cluster/wire/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ package wire

import (
"github.com/ethereum/go-ethereum/qkc/account"
qkcCommon "github.com/ethereum/go-ethereum/qkc/common"
"github.com/ethereum/go-ethereum/qkc/serialize"
"github.com/ethereum/go-ethereum/qkc/types"
)

// =============================================================================
Expand Down Expand Up @@ -118,9 +120,9 @@ const UInt128Length = 16
// ("root_tip", Optional(RootBlock)),
// ]
type PingRequest struct {
ID []byte `bytesizeofslicelen:"4"`
FullShardIDList []uint32 `bytesizeofslicelen:"4"`
RootTip *RawBytes `ser:"nil"` // TODO: Replace with *RootBlock once core.RootBlock is ported
ID []byte `bytesizeofslicelen:"4"`
FullShardIDList []uint32 `bytesizeofslicelen:"4"`
RootTip *types.RootBlock `ser:"nil"`
}

// PongResponse (ClusterOp.PONG, 0x82) — slave's reply to PING.
Expand Down Expand Up @@ -200,7 +202,7 @@ type MineResponse struct {
type GenTxRequest struct {
NumTxPerShard uint32
XShardPercent uint32
Tx *RawBytes // TODO: Replace with *TypedTransaction once core.TypedTransaction is ported
Tx *types.Transaction
}

// GenTxResponse (ClusterOp.GEN_TX_RESPONSE, 0xAA).
Expand Down Expand Up @@ -236,8 +238,7 @@ type DestroyClusterPeerConnectionCommand struct {
//
// FIELDS = [("root_block", RootBlock), ("expect_switch", boolean)]
type AddRootBlockRequest struct {
// TODO: Replace with *RootBlock once core.RootBlock is ported.
RootBlock *RawBytes
RootBlock *types.RootBlock
ExpectSwitch bool
}

Expand Down Expand Up @@ -289,7 +290,7 @@ type GetNextBlockToMineRequest struct {
// GetNextBlockToMineResponse (ClusterOp.GET_NEXT_BLOCK_TO_MINE_RESPONSE, 0x8A).
type GetNextBlockToMineResponse struct {
ErrorCode uint32
Block *RawBytes // TODO: Replace with *MinorBlock once core.MinorBlock is ported
Block *types.MinorBlock
}

// AddMinorBlockRequest (ClusterOp.ADD_MINOR_BLOCK_REQUEST, 0x97) — JRPC-mined blocks.
Expand All @@ -306,7 +307,7 @@ type AddMinorBlockResponse struct {

// CheckMinorBlockRequest (ClusterOp.CHECK_MINOR_BLOCK_REQUEST, 0xBD).
type CheckMinorBlockRequest struct {
MinorBlockHeader *RawBytes // TODO: Replace with *MinorBlockHeader once core.MinorBlockHeader is ported
MinorBlockHeader *types.MinorBlockHeader
}

// CheckMinorBlockResponse (ClusterOp.CHECK_MINOR_BLOCK_RESPONSE, 0xBE).
Expand All @@ -317,7 +318,7 @@ type CheckMinorBlockResponse struct {
// HeadersInfo — used by GetUnconfirmedHeadersResponse.
type HeadersInfo struct {
Branch uint32
HeaderList []*RawBytes `bytesizeofslicelen:"4"` // TODO: Replace with []*MinorBlockHeader once core.MinorBlockHeader is ported
HeaderList []*types.MinorBlockHeader `bytesizeofslicelen:"4"`
}

// GetUnconfirmedHeadersRequest (ClusterOp.GET_UNCONFIRMED_HEADERS_REQUEST, 0x8B) — empty body.
Expand All @@ -340,10 +341,9 @@ type GetUnconfirmedHeadersResponse struct {
// ("mined_blocks", uint16),
// ]
type AccountBranchData struct {
Branch uint32
TransactionCount serialize.Uint256
// TODO: Replace with *TokenBalanceMap once core.TokenBalanceMap is ported.
TokenBalances *RawBytes
Branch uint32
TransactionCount serialize.Uint256
TokenBalances *qkcCommon.TokenBalances
IsContract bool
PoswMineableBlocks uint16
MinedBlocks uint16
Expand All @@ -363,7 +363,7 @@ type GetAccountDataResponse struct {

// AddTransactionRequest (ClusterOp.ADD_TRANSACTION_REQUEST, 0x8F).
type AddTransactionRequest struct {
Tx *RawBytes // TODO: Replace with *TypedTransaction once core.TypedTransaction is ported
Tx *types.Transaction
}

// AddTransactionResponse (ClusterOp.ADD_TRANSACTION_RESPONSE, 0x90).
Expand Down Expand Up @@ -410,12 +410,10 @@ type ShardStats struct {
// ("shard_stats", ShardStats),
// ]
type AddMinorBlockHeaderRequest struct {
// TODO: Replace with *MinorBlockHeader once core.MinorBlockHeader is ported.
MinorBlockHeader *RawBytes
TxCount uint32
XShardTxCount uint32
// TODO: Replace with *TokenBalanceMap once core.TokenBalanceMap is ported.
CoinbaseAmountMap *RawBytes
MinorBlockHeader *types.MinorBlockHeader
TxCount uint32
XShardTxCount uint32
CoinbaseAmountMap *qkcCommon.TokenBalances
ShardStats ShardStats
}

Expand All @@ -427,8 +425,8 @@ type AddMinorBlockHeaderResponse struct {

// AddMinorBlockHeaderListRequest (ClusterOp.ADD_MINOR_BLOCK_HEADER_LIST_REQUEST, 0xBB) — slave→master.
type AddMinorBlockHeaderListRequest struct {
MinorBlockHeaderList []*RawBytes `bytesizeofslicelen:"4"` // TODO: Replace with []*MinorBlockHeader once core.MinorBlockHeader is ported
CoinbaseAmountMapList []*RawBytes `bytesizeofslicelen:"4"` // TODO: Replace with []*TokenBalanceMap once core.TokenBalanceMap is ported
MinorBlockHeaderList []*types.MinorBlockHeader `bytesizeofslicelen:"4"`
CoinbaseAmountMapList []*qkcCommon.TokenBalances `bytesizeofslicelen:"4"`
}

// AddMinorBlockHeaderListResponse (ClusterOp.ADD_MINOR_BLOCK_HEADER_LIST_RESPONSE, 0xBC).
Expand Down Expand Up @@ -480,9 +478,8 @@ type GetMinorBlockRequest struct {

// GetMinorBlockResponse (ClusterOp.GET_MINOR_BLOCK_RESPONSE, 0x9E).
type GetMinorBlockResponse struct {
ErrorCode uint32
// TODO: Replace with *MinorBlock once core.MinorBlock is ported.
MinorBlock *RawBytes
ErrorCode uint32
MinorBlock *types.MinorBlock
ExtraInfo *MinorBlockExtraInfo `ser:"nil"`
}

Expand All @@ -494,16 +491,14 @@ type GetTransactionRequest struct {

// GetTransactionResponse (ClusterOp.GET_TRANSACTION_RESPONSE, 0xA0).
type GetTransactionResponse struct {
ErrorCode uint32
// TODO: Replace with *MinorBlock once core.MinorBlock is ported.
MinorBlock *RawBytes
ErrorCode uint32
MinorBlock *types.MinorBlock
Index uint32
}

// ExecuteTransactionRequest (ClusterOp.EXECUTE_TRANSACTION_REQUEST, 0xA3).
type ExecuteTransactionRequest struct {
// TODO: Replace with *TypedTransaction once core.TypedTransaction is ported.
Tx *RawBytes
Tx *types.Transaction
FromAddress account.Address
BlockHeight *uint64 `ser:"nil"`
}
Expand All @@ -522,12 +517,10 @@ type GetTransactionReceiptRequest struct {

// GetTransactionReceiptResponse (ClusterOp.GET_TRANSACTION_RECEIPT_RESPONSE, 0xA6).
type GetTransactionReceiptResponse struct {
ErrorCode uint32
// TODO: Replace with *MinorBlock once core.MinorBlock is ported.
MinorBlock *RawBytes
ErrorCode uint32
MinorBlock *types.MinorBlock
Index uint32
// TODO: Replace with *TransactionReceipt once core.TransactionReceipt is ported.
Receipt *RawBytes
Receipt *types.ClusterTransactionReceipt
}

// TransactionDetail — used by GetTransactionListByAddressResponse and
Expand Down Expand Up @@ -595,13 +588,12 @@ type GetLogRequest struct {
// GetLogResponse (ClusterOp.GET_LOG_RESPONSE, 0xAE).
type GetLogResponse struct {
ErrorCode uint32
Logs []*RawBytes `bytesizeofslicelen:"4"` // TODO: Replace with []*Log once core.Log is ported
Logs []*types.ClusterLog `bytesizeofslicelen:"4"`
}

// EstimateGasRequest (ClusterOp.ESTIMATE_GAS_REQUEST, 0xAF).
type EstimateGasRequest struct {
// TODO: Replace with *TypedTransaction once core.TypedTransaction is ported.
Tx *RawBytes
Tx *types.Transaction
FromAddress account.Address
}

Expand Down Expand Up @@ -719,7 +711,7 @@ type GetTotalBalanceResponse struct {
type AddXshardTxListRequest struct {
Branch uint32
MinorBlockHash [HashLength]byte
TxList *RawBytes // TODO: Replace with *CrossShardTransactionList once core.CrossShardTransactionList is ported
TxList *types.CrossShardTransactionList
}

// AddXshardTxListResponse (ClusterOp.ADD_XSHARD_TX_LIST_RESPONSE, 0x94).
Expand Down Expand Up @@ -754,32 +746,30 @@ type BatchAddXshardTxListResponse struct {
// ("genesis_root_block_hash", hash256),
// ]
type HelloCommand struct {
Version uint32
NetworkID uint32
PeerID [HashLength]byte
PeerIP [UInt128Length]byte
PeerPort uint16
ChainMaskList []uint32 `bytesizeofslicelen:"4"`
// TODO: Replace with *RootBlockHeader once core.RootBlockHeader is ported.
RootBlockHeader *RawBytes
Version uint32
NetworkID uint32
PeerID [HashLength]byte
PeerIP [UInt128Length]byte
PeerPort uint16
ChainMaskList []uint32 `bytesizeofslicelen:"4"`
RootBlockHeader *types.RootBlockHeader
GenesisRootBlockHash [HashLength]byte
}

// NewMinorBlockHeaderListCommand (CommandOp.NEW_MINOR_BLOCK_HEADER_LIST, 0x01).
type NewMinorBlockHeaderListCommand struct {
// TODO: Replace with *RootBlockHeader once core.RootBlockHeader is ported.
RootBlockHeader *RawBytes
MinorBlockHeaderList []*RawBytes `bytesizeofslicelen:"4"` // TODO: Replace with []*MinorBlockHeader once core.MinorBlockHeader is ported
RootBlockHeader *types.RootBlockHeader
MinorBlockHeaderList []*types.MinorBlockHeader `bytesizeofslicelen:"4"`
}

// NewTransactionListCommand (CommandOp.NEW_TRANSACTION_LIST, 0x02).
type NewTransactionListCommand struct {
TransactionList []*RawBytes `bytesizeofslicelen:"4"` // TODO: Replace with []*TypedTransaction once core.TypedTransaction is ported
TransactionList []*types.Transaction `bytesizeofslicelen:"4"`
}

// NewBlockMinorCommand (CommandOp.NEW_BLOCK_MINOR, 0x0D).
type NewBlockMinorCommand struct {
Block *RawBytes // TODO: Replace with *MinorBlock once core.MinorBlock is ported
Block *types.MinorBlock
}

// PingPongCommand (CommandOp.PING 0x0E, PONG 0x0F).
Expand All @@ -789,7 +779,7 @@ type PingPongCommand struct {

// NewRootBlockCommand (CommandOp.NEW_ROOT_BLOCK, 0x12).
type NewRootBlockCommand struct {
Block *RawBytes // TODO: Replace with *RootBlock once core.RootBlock is ported
Block *types.RootBlock
}

// =============================================================================
Expand Down Expand Up @@ -821,9 +811,8 @@ type GetRootBlockHeaderListRequest struct {

// GetRootBlockHeaderListResponse (CommandOp.GET_ROOT_BLOCK_HEADER_LIST_RESPONSE, 0x06).
type GetRootBlockHeaderListResponse struct {
// TODO: Replace with *RootBlockHeader once core.RootBlockHeader is ported.
RootTip *RawBytes
BlockHeaderList []*RawBytes `bytesizeofslicelen:"4"` // TODO: Replace with []*RootBlockHeader once core.RootBlockHeader is ported
RootTip *types.RootBlockHeader
BlockHeaderList []*types.RootBlockHeader `bytesizeofslicelen:"4"`
}

// GetRootBlockHeaderListWithSkipRequest (CommandOp.GET_ROOT_BLOCK_HEADER_LIST_WITH_SKIP_REQUEST, 0x10).
Expand All @@ -842,7 +831,7 @@ type GetRootBlockListRequest struct {

// GetRootBlockListResponse (CommandOp.GET_ROOT_BLOCK_LIST_RESPONSE, 0x08).
type GetRootBlockListResponse struct {
RootBlockList []*RawBytes `bytesizeofslicelen:"4"` // TODO: Replace with []*RootBlock once core.RootBlock is ported
RootBlockList []*types.RootBlock `bytesizeofslicelen:"4"`
}

// GetMinorBlockListRequest (CommandOp.GET_MINOR_BLOCK_LIST_REQUEST, 0x09).
Expand All @@ -852,7 +841,7 @@ type GetMinorBlockListRequest struct {

// GetMinorBlockListResponse (CommandOp.GET_MINOR_BLOCK_LIST_RESPONSE, 0x0A).
type GetMinorBlockListResponse struct {
MinorBlockList []*RawBytes `bytesizeofslicelen:"4"` // TODO: Replace with []*MinorBlock once core.MinorBlock is ported
MinorBlockList []*types.MinorBlock `bytesizeofslicelen:"4"`
}

// GetMinorBlockHeaderListRequest (CommandOp.GET_MINOR_BLOCK_HEADER_LIST_REQUEST, 0x0B).
Expand All @@ -865,11 +854,9 @@ type GetMinorBlockHeaderListRequest struct {

// GetMinorBlockHeaderListResponse (CommandOp.GET_MINOR_BLOCK_HEADER_LIST_RESPONSE, 0x0C).
type GetMinorBlockHeaderListResponse struct {
// TODO: Replace with *RootBlockHeader once core.RootBlockHeader is ported.
RootTip *RawBytes
// TODO: Replace with *MinorBlockHeader once core.MinorBlockHeader is ported.
ShardTip *RawBytes
BlockHeaderList []*RawBytes `bytesizeofslicelen:"4"` // TODO: Replace with []*MinorBlockHeader once core.MinorBlockHeader is ported
RootTip *types.RootBlockHeader
ShardTip *types.MinorBlockHeader
BlockHeaderList []*types.MinorBlockHeader `bytesizeofslicelen:"4"`
}

// GetMinorBlockHeaderListWithSkipRequest (CommandOp.GET_MINOR_BLOCK_HEADER_LIST_WITH_SKIP_REQUEST, 0x13).
Expand Down
8 changes: 5 additions & 3 deletions qkc/cluster/wire/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

"github.com/ethereum/go-ethereum/qkc/account"
"github.com/ethereum/go-ethereum/qkc/serialize"
"github.com/ethereum/go-ethereum/qkc/types"
)

// =============================================================================
Expand Down Expand Up @@ -103,14 +104,15 @@ func TestMessageRoundTrip(t *testing.T) {
name string
msg any
}{
{"PingRequest_no_RawBytes", PingRequest{
{"PingRequest_no_RootTip", PingRequest{
ID: []byte("slave1"),
FullShardIDList: []uint32{0x00010001, 0x00020002},
}},
{"GenTxRequest_RawBytes_last", GenTxRequest{
{"GenTxRequest_Tx_last", GenTxRequest{
NumTxPerShard: 10,
XShardPercent: 30,
Tx: &RawBytes{0x01, 0x02, 0x03},
Tx: types.NewEvmTransaction(1, account.Recipient{}, big.NewInt(100), 21000, big.NewInt(10),
0x00010001, 0x00010002, 1, 1, []byte{0xAA}, 1, 1),
}},
}

Expand Down