refactor(order): refactor order module transaction type
This commit is contained in:
parent
52e758e5dc
commit
6c7a01d1e6
5
go.mod
5
go.mod
|
@ -2,7 +2,6 @@ module github.com/meshplus/bitxhub
|
|||
|
||||
require (
|
||||
github.com/Rican7/retry v0.1.0
|
||||
github.com/bitxhub/parallel-executor v0.0.0-20201016065313-8057d544998e
|
||||
github.com/cbergoon/merkletree v0.2.0
|
||||
github.com/common-nighthawk/go-figure v0.0.0-20190529165535-67e0ed34491a
|
||||
github.com/coreos/etcd v3.3.18+incompatible
|
||||
|
@ -20,8 +19,8 @@ require (
|
|||
github.com/libp2p/go-libp2p-core v0.5.6
|
||||
github.com/magiconair/properties v1.8.1
|
||||
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20201021060002-1c1bbd9b125b
|
||||
github.com/meshplus/bitxhub-kit v1.1.1
|
||||
github.com/meshplus/bitxhub-model v1.1.2-0.20201021105923-65b4f2c37d91
|
||||
github.com/meshplus/bitxhub-kit v1.1.2-0.20201021090332-9830eaa971d4
|
||||
github.com/meshplus/bitxhub-model v1.1.2-0.20201021121200-409ba3cf9d4b
|
||||
github.com/meshplus/go-lightp2p v0.0.0-20200817105923-6b3aee40fa54
|
||||
github.com/mitchellh/go-homedir v1.1.0
|
||||
github.com/multiformats/go-multiaddr v0.2.2
|
||||
|
|
4
go.sum
4
go.sum
|
@ -584,6 +584,8 @@ github.com/meshplus/bitxhub-kit v1.0.1-0.20200903112208-fb288271c55c/go.mod h1:8
|
|||
github.com/meshplus/bitxhub-kit v1.0.1-0.20200914065214-5161497a783c/go.mod h1:Whtgcr25HOF6iJv0Ib5/BPnEXq9iNFO89j8JQkElISk=
|
||||
github.com/meshplus/bitxhub-kit v1.1.1 h1:vkPO88oA3+Kpc0N8lIgfj/U52KBuI+633hPbMYt1xm8=
|
||||
github.com/meshplus/bitxhub-kit v1.1.1/go.mod h1:r4l4iqn0RPJreb/OmoYKfjCjQJrXpZX++6Qc31VG/1k=
|
||||
github.com/meshplus/bitxhub-kit v1.1.2-0.20201021090332-9830eaa971d4 h1:4nlHdSmzaigzpeMS/bcP60T5/Hwnv3TmGLRFf+9k1t8=
|
||||
github.com/meshplus/bitxhub-kit v1.1.2-0.20201021090332-9830eaa971d4/go.mod h1:r4l4iqn0RPJreb/OmoYKfjCjQJrXpZX++6Qc31VG/1k=
|
||||
github.com/meshplus/bitxhub-model v1.0.0-rc3/go.mod h1:ZCctQIYTlE3vJ8Lhkrgs9bWwNA+Dw4JzojOSIzLVU6E=
|
||||
github.com/meshplus/bitxhub-model v1.0.0-rc4.0.20200514093243-7e8ae60d1c19/go.mod h1:QK8aACbxtZEA3Hk1BOCirW0uxMWLsMrLDpWz9FweIKM=
|
||||
github.com/meshplus/bitxhub-model v1.0.0-rc4.0.20201009112846-79d2e6ddf10d h1:q4Vig+IVhBvARLyeOsFw8gAdor0ajiBl6lGch1N65sk=
|
||||
|
@ -592,6 +594,8 @@ github.com/meshplus/bitxhub-model v1.1.1 h1:/0Si29e14YW1GUbkJbCL8A70yXzxyiV/u36k
|
|||
github.com/meshplus/bitxhub-model v1.1.1/go.mod h1:lUl9vPZXM9tP+B0ABRW/2eOW/6KCmjFTdoiTj5Vut/A=
|
||||
github.com/meshplus/bitxhub-model v1.1.2-0.20201021105923-65b4f2c37d91 h1:MmB0+GRA2Env71QMSDhGNCbbSDdoC8ybTIkqBUxeEAk=
|
||||
github.com/meshplus/bitxhub-model v1.1.2-0.20201021105923-65b4f2c37d91/go.mod h1:lUl9vPZXM9tP+B0ABRW/2eOW/6KCmjFTdoiTj5Vut/A=
|
||||
github.com/meshplus/bitxhub-model v1.1.2-0.20201021121200-409ba3cf9d4b h1:cyK/HwEygdDhZGXUVzd/EoqXmL38dBum1aWEwj7IPks=
|
||||
github.com/meshplus/bitxhub-model v1.1.2-0.20201021121200-409ba3cf9d4b/go.mod h1:lUl9vPZXM9tP+B0ABRW/2eOW/6KCmjFTdoiTj5Vut/A=
|
||||
github.com/meshplus/go-bitxhub-client v1.0.0-rc3/go.mod h1:FpiCyf6KhydcqthrHdvvPhbPIcD92b+Ju8T7WvQtSyM=
|
||||
github.com/meshplus/go-lightp2p v0.0.0-20200817105923-6b3aee40fa54 h1:5Ip5AB7SxxQHg5SRtf2cCOI2wy1p75MQB12soPtPyf8=
|
||||
github.com/meshplus/go-lightp2p v0.0.0-20200817105923-6b3aee40fa54/go.mod h1:G89UJaeqCQFxFdp8wzy1AdKfMtDEhpySau0pjDNeeaw=
|
||||
|
|
|
@ -15,7 +15,7 @@ const (
|
|||
)
|
||||
|
||||
func (addr BoltContractAddress) Address() *types.Address {
|
||||
return types.String2Address(string(addr))
|
||||
return types.NewAddressByStr(string(addr))
|
||||
}
|
||||
|
||||
func (addr BoltContractAddress) String() string {
|
||||
|
|
|
@ -168,7 +168,6 @@ func (n *Node) ReportState(height uint64, hash types.Hash) {
|
|||
if height%10 == 0 {
|
||||
n.logger.WithFields(logrus.Fields{
|
||||
"height": height,
|
||||
"hash": hash.ShortString(),
|
||||
}).Info("Report checkpoint")
|
||||
}
|
||||
appliedIndex, ok := n.blockAppliedIndex.Load(height)
|
||||
|
|
|
@ -40,7 +40,7 @@ func TestNode_Start(t *testing.T) {
|
|||
|
||||
var ID uint64 = 1
|
||||
nodes := make(map[uint64]types.Address)
|
||||
nodes[ID] = types.String2Address("")
|
||||
nodes[ID] = *types.NewAddressByStr("")
|
||||
|
||||
fileData, err := ioutil.ReadFile("../../../config/order.toml")
|
||||
require.Nil(t, err)
|
||||
|
@ -160,10 +160,7 @@ func generateTx() *pb.Transaction {
|
|||
|
||||
tx := &pb.Transaction{
|
||||
From: from,
|
||||
To: types.String2Address(to),
|
||||
Data: &pb.TransactionData{
|
||||
Amount: 10,
|
||||
},
|
||||
To: types.NewAddressByStr(to),
|
||||
Timestamp: time.Now().UnixNano(),
|
||||
Nonce: 1,
|
||||
}
|
||||
|
@ -277,7 +274,7 @@ func newSwarms(t *testing.T, peerCnt int) ([]*peermgr.Swarm, map[uint64]types.Ad
|
|||
|
||||
address, err := privKeys[i].PublicKey().Address()
|
||||
require.Nil(t, err)
|
||||
nodes[uint64(ID)] = address
|
||||
nodes[uint64(ID)] = *address
|
||||
swarm, err := peermgr.New(repo, log.NewWithModule("p2p"), mockLedger)
|
||||
require.Nil(t, err)
|
||||
err = swarm.Start()
|
||||
|
|
|
@ -10,7 +10,6 @@ import (
|
|||
github_com_meshplus_bitxhub_kit_types "github.com/meshplus/bitxhub-kit/types"
|
||||
io "io"
|
||||
math "math"
|
||||
math_bits "math/bits"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
|
@ -22,7 +21,7 @@ var _ = math.Inf
|
|||
// is compatible with the proto package it is being compiled against.
|
||||
// A compilation error at this line likely means your copy of the
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
|
||||
const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package
|
||||
|
||||
type RaftMessage_Type int32
|
||||
|
||||
|
@ -75,7 +74,7 @@ func (m *RaftMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
|
|||
return xxx_messageInfo_RaftMessage.Marshal(b, m, deterministic)
|
||||
} else {
|
||||
b = b[:cap(b)]
|
||||
n, err := m.MarshalToSizedBuffer(b)
|
||||
n, err := m.MarshalTo(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -116,7 +115,7 @@ func (m *RaftMessage) GetData() []byte {
|
|||
}
|
||||
|
||||
type Ready struct {
|
||||
TxHashes []github_com_meshplus_bitxhub_kit_types.Hash `protobuf:"bytes,1,rep,name=txHashes,proto3,customtype=github.com/meshplus/bitxhub-kit/types.Hash" json:"txHashes"`
|
||||
TxHashes []github_com_meshplus_bitxhub_kit_types.Hash `protobuf:"bytes,1,rep,name=txHashes,proto3,customtype=github.com/meshplus/bitxhub-kit/types.Hash" json:"txHashes,omitempty"`
|
||||
Height uint64 `protobuf:"varint,2,opt,name=height,proto3" json:"height,omitempty"`
|
||||
}
|
||||
|
||||
|
@ -134,7 +133,7 @@ func (m *Ready) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
|||
return xxx_messageInfo_Ready.Marshal(b, m, deterministic)
|
||||
} else {
|
||||
b = b[:cap(b)]
|
||||
n, err := m.MarshalToSizedBuffer(b)
|
||||
n, err := m.MarshalTo(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -169,34 +168,33 @@ func init() {
|
|||
func init() { proto.RegisterFile("message.proto", fileDescriptor_33c57e4bae7b9afd) }
|
||||
|
||||
var fileDescriptor_33c57e4bae7b9afd = []byte{
|
||||
// 321 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0xd1, 0x6a, 0xf2, 0x30,
|
||||
0x1c, 0xc5, 0x1b, 0xad, 0xf2, 0x7d, 0xff, 0xa9, 0x94, 0x5c, 0x6c, 0x65, 0x17, 0xb5, 0x78, 0x55,
|
||||
0x36, 0x6c, 0xc1, 0x3d, 0x81, 0x76, 0xb2, 0x8d, 0x31, 0x85, 0xd4, 0xc1, 0xee, 0xa4, 0x9d, 0xb1,
|
||||
0x29, 0x5b, 0x49, 0x31, 0x29, 0xe8, 0x5b, 0xec, 0x3d, 0xf6, 0x22, 0x5e, 0x7a, 0x39, 0x76, 0x21,
|
||||
0xc3, 0xbe, 0xc8, 0x68, 0xba, 0x0d, 0xaf, 0x72, 0x7e, 0xe1, 0x9c, 0x43, 0x4e, 0xa0, 0x9d, 0x52,
|
||||
0x21, 0xc2, 0x98, 0xba, 0xd9, 0x8a, 0x4b, 0x8e, 0x1b, 0xea, 0x38, 0xef, 0xc7, 0x89, 0x64, 0x79,
|
||||
0xe4, 0x3e, 0xf3, 0xd4, 0x8b, 0x79, 0xcc, 0x3d, 0x75, 0x1d, 0xe5, 0x4b, 0x45, 0x0a, 0x94, 0xaa,
|
||||
0x52, 0xbd, 0x77, 0x04, 0x27, 0x24, 0x5c, 0xca, 0x87, 0xaa, 0x0b, 0x5f, 0x82, 0x2e, 0x37, 0x19,
|
||||
0x35, 0x91, 0x8d, 0x9c, 0xce, 0xe0, 0xac, 0x72, 0xb9, 0x47, 0x0e, 0x77, 0xb6, 0xc9, 0x28, 0x51,
|
||||
0x26, 0x7c, 0x0a, 0xcd, 0xe5, 0x8a, 0xa7, 0x77, 0x0b, 0xb3, 0x66, 0x23, 0x47, 0x27, 0x3f, 0x84,
|
||||
0x31, 0xe8, 0x8b, 0x50, 0x86, 0x66, 0xdd, 0x46, 0x4e, 0x8b, 0x28, 0xdd, 0xf3, 0x41, 0x2f, 0x93,
|
||||
0xb8, 0x0d, 0xff, 0xfd, 0xe9, 0x24, 0x18, 0x4f, 0x82, 0xc7, 0xc0, 0xd0, 0xb0, 0x01, 0xad, 0x11,
|
||||
0x99, 0x0e, 0xaf, 0xfd, 0x61, 0x30, 0x9b, 0xcf, 0x9e, 0x0c, 0x84, 0x01, 0x9a, 0x37, 0x63, 0xa5,
|
||||
0x6b, 0xb8, 0x03, 0x50, 0xe9, 0xf9, 0xd0, 0xbf, 0x37, 0xea, 0x3d, 0x0e, 0x0d, 0x42, 0xc3, 0xc5,
|
||||
0x06, 0x4f, 0xe0, 0x9f, 0x5c, 0xdf, 0x86, 0x82, 0x51, 0x61, 0x22, 0xbb, 0xee, 0xb4, 0x46, 0x83,
|
||||
0xed, 0xbe, 0xab, 0x7d, 0xee, 0xbb, 0x17, 0x47, 0xfb, 0x53, 0x2a, 0x58, 0xf6, 0x9a, 0x0b, 0x2f,
|
||||
0x4a, 0xe4, 0x9a, 0xe5, 0x51, 0xff, 0x25, 0x91, 0x5e, 0xf9, 0x72, 0xe1, 0x96, 0x59, 0xf2, 0xd7,
|
||||
0x51, 0x2e, 0x61, 0x34, 0x89, 0x99, 0xfc, 0x5d, 0x52, 0xd1, 0xc8, 0xdc, 0x1e, 0x2c, 0xb4, 0x3b,
|
||||
0x58, 0xe8, 0xeb, 0x60, 0xa1, 0xb7, 0xc2, 0xd2, 0x76, 0x85, 0xa5, 0x7d, 0x14, 0x96, 0x16, 0x35,
|
||||
0xd5, 0xcf, 0x5c, 0x7d, 0x07, 0x00, 0x00, 0xff, 0xff, 0x4f, 0x14, 0xbe, 0x1f, 0x86, 0x01, 0x00,
|
||||
0x00,
|
||||
// 318 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0xcf, 0x4a, 0xf3, 0x40,
|
||||
0x14, 0xc5, 0x33, 0x6d, 0x5a, 0xbe, 0xef, 0xda, 0x96, 0x30, 0x0b, 0x0d, 0x2e, 0x62, 0xe8, 0x2a,
|
||||
0x28, 0x4d, 0x40, 0x9f, 0xa0, 0x8d, 0xc5, 0x7f, 0xd8, 0xc2, 0xa4, 0x82, 0xbb, 0x32, 0xb1, 0xd3,
|
||||
0x4c, 0xa8, 0x61, 0x42, 0x67, 0x02, 0xed, 0x5b, 0xf8, 0x1e, 0xbe, 0x88, 0xcb, 0x2e, 0xc5, 0x85,
|
||||
0x48, 0xfb, 0x22, 0x92, 0x89, 0x4a, 0x57, 0x73, 0xce, 0x70, 0x7e, 0x97, 0x7b, 0x2e, 0xb4, 0x33,
|
||||
0x26, 0x25, 0x4d, 0x98, 0x9f, 0x2f, 0x85, 0x12, 0xb8, 0xa1, 0x9f, 0xe3, 0x5e, 0x92, 0x2a, 0x5e,
|
||||
0xc4, 0xfe, 0x93, 0xc8, 0x82, 0x44, 0x24, 0x22, 0xd0, 0xdf, 0x71, 0x31, 0xd7, 0x4e, 0x1b, 0xad,
|
||||
0x2a, 0xaa, 0xfb, 0x8a, 0xe0, 0x80, 0xd0, 0xb9, 0xba, 0xaf, 0x66, 0xe1, 0x33, 0x30, 0xd5, 0x3a,
|
||||
0x67, 0x36, 0x72, 0x91, 0xd7, 0x39, 0x3f, 0xaa, 0x52, 0xfe, 0x5e, 0xc2, 0x9f, 0xac, 0x73, 0x46,
|
||||
0x74, 0x08, 0x1f, 0x42, 0x73, 0xbe, 0x14, 0xd9, 0xcd, 0xcc, 0xae, 0xb9, 0xc8, 0x33, 0xc9, 0x8f,
|
||||
0xc3, 0x18, 0xcc, 0x19, 0x55, 0xd4, 0xae, 0xbb, 0xc8, 0x6b, 0x11, 0xad, 0xbb, 0x21, 0x98, 0x25,
|
||||
0x89, 0xdb, 0xf0, 0x3f, 0x1c, 0x8f, 0xa2, 0xe1, 0x28, 0x7a, 0x88, 0x2c, 0x03, 0x5b, 0xd0, 0x1a,
|
||||
0x90, 0x71, 0xff, 0x32, 0xec, 0x47, 0x93, 0xe9, 0xe4, 0xd1, 0x42, 0x18, 0xa0, 0x79, 0x35, 0xd4,
|
||||
0xba, 0x86, 0x3b, 0x00, 0x95, 0x9e, 0xf6, 0xc3, 0x3b, 0xab, 0xde, 0x5d, 0x40, 0x83, 0x30, 0x3a,
|
||||
0x5b, 0xe3, 0x5b, 0xf8, 0xa7, 0x56, 0xd7, 0x54, 0x72, 0x26, 0x6d, 0xe4, 0xd6, 0xbd, 0xd6, 0xc0,
|
||||
0xff, 0xf8, 0x3c, 0x39, 0xdd, 0xeb, 0x9e, 0x31, 0xc9, 0xf3, 0xe7, 0x42, 0x06, 0x71, 0xaa, 0x56,
|
||||
0xbc, 0x88, 0x7b, 0x8b, 0x54, 0x05, 0xe5, 0xd6, 0xd2, 0x2f, 0x39, 0xf2, 0xc7, 0x97, 0x2d, 0x38,
|
||||
0x4b, 0x13, 0xae, 0x7e, 0x5b, 0x54, 0x6e, 0x60, 0xbf, 0x6d, 0x1d, 0xb4, 0xd9, 0x3a, 0xe8, 0x6b,
|
||||
0xeb, 0xa0, 0x97, 0x9d, 0x63, 0x6c, 0x76, 0x8e, 0xf1, 0xbe, 0x73, 0x8c, 0xb8, 0xa9, 0xaf, 0x72,
|
||||
0xf1, 0x1d, 0x00, 0x00, 0xff, 0xff, 0xec, 0x5d, 0x36, 0x19, 0x82, 0x01, 0x00, 0x00,
|
||||
}
|
||||
|
||||
func (m *RaftMessage) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||
n, err := m.MarshalTo(dAtA)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -204,39 +202,33 @@ func (m *RaftMessage) Marshal() (dAtA []byte, err error) {
|
|||
}
|
||||
|
||||
func (m *RaftMessage) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *RaftMessage) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
var i int
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.Data) > 0 {
|
||||
i -= len(m.Data)
|
||||
copy(dAtA[i:], m.Data)
|
||||
i = encodeVarintMessage(dAtA, i, uint64(len(m.Data)))
|
||||
i--
|
||||
dAtA[i] = 0x1a
|
||||
if m.Type != 0 {
|
||||
dAtA[i] = 0x8
|
||||
i++
|
||||
i = encodeVarintMessage(dAtA, i, uint64(m.Type))
|
||||
}
|
||||
if m.FromId != 0 {
|
||||
i = encodeVarintMessage(dAtA, i, uint64(m.FromId))
|
||||
i--
|
||||
dAtA[i] = 0x10
|
||||
i++
|
||||
i = encodeVarintMessage(dAtA, i, uint64(m.FromId))
|
||||
}
|
||||
if m.Type != 0 {
|
||||
i = encodeVarintMessage(dAtA, i, uint64(m.Type))
|
||||
i--
|
||||
dAtA[i] = 0x8
|
||||
if len(m.Data) > 0 {
|
||||
dAtA[i] = 0x1a
|
||||
i++
|
||||
i = encodeVarintMessage(dAtA, i, uint64(len(m.Data)))
|
||||
i += copy(dAtA[i:], m.Data)
|
||||
}
|
||||
return len(dAtA) - i, nil
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func (m *Ready) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||
n, err := m.MarshalTo(dAtA)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -244,47 +236,38 @@ func (m *Ready) Marshal() (dAtA []byte, err error) {
|
|||
}
|
||||
|
||||
func (m *Ready) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *Ready) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
var i int
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if m.Height != 0 {
|
||||
i = encodeVarintMessage(dAtA, i, uint64(m.Height))
|
||||
i--
|
||||
dAtA[i] = 0x10
|
||||
}
|
||||
if len(m.TxHashes) > 0 {
|
||||
for iNdEx := len(m.TxHashes) - 1; iNdEx >= 0; iNdEx-- {
|
||||
{
|
||||
size := m.TxHashes[iNdEx].Size()
|
||||
i -= size
|
||||
if _, err := m.TxHashes[iNdEx].MarshalTo(dAtA[i:]); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i = encodeVarintMessage(dAtA, i, uint64(size))
|
||||
}
|
||||
i--
|
||||
for _, msg := range m.TxHashes {
|
||||
dAtA[i] = 0xa
|
||||
i++
|
||||
i = encodeVarintMessage(dAtA, i, uint64(msg.Size()))
|
||||
n, err := msg.MarshalTo(dAtA[i:])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i += n
|
||||
}
|
||||
}
|
||||
return len(dAtA) - i, nil
|
||||
if m.Height != 0 {
|
||||
dAtA[i] = 0x10
|
||||
i++
|
||||
i = encodeVarintMessage(dAtA, i, uint64(m.Height))
|
||||
}
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func encodeVarintMessage(dAtA []byte, offset int, v uint64) int {
|
||||
offset -= sovMessage(v)
|
||||
base := offset
|
||||
for v >= 1<<7 {
|
||||
dAtA[offset] = uint8(v&0x7f | 0x80)
|
||||
v >>= 7
|
||||
offset++
|
||||
}
|
||||
dAtA[offset] = uint8(v)
|
||||
return base
|
||||
return offset + 1
|
||||
}
|
||||
func (m *RaftMessage) Size() (n int) {
|
||||
if m == nil {
|
||||
|
@ -324,7 +307,14 @@ func (m *Ready) Size() (n int) {
|
|||
}
|
||||
|
||||
func sovMessage(x uint64) (n int) {
|
||||
return (math_bits.Len64(x|1) + 6) / 7
|
||||
for {
|
||||
n++
|
||||
x >>= 7
|
||||
if x == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
func sozMessage(x uint64) (n int) {
|
||||
return sovMessage(uint64((x << 1) ^ uint64((int64(x) >> 63))))
|
||||
|
@ -564,7 +554,6 @@ func (m *Ready) Unmarshal(dAtA []byte) error {
|
|||
func skipMessage(dAtA []byte) (n int, err error) {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
depth := 0
|
||||
for iNdEx < l {
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
|
@ -596,8 +585,10 @@ func skipMessage(dAtA []byte) (n int, err error) {
|
|||
break
|
||||
}
|
||||
}
|
||||
return iNdEx, nil
|
||||
case 1:
|
||||
iNdEx += 8
|
||||
return iNdEx, nil
|
||||
case 2:
|
||||
var length int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
|
@ -618,30 +609,55 @@ func skipMessage(dAtA []byte) (n int, err error) {
|
|||
return 0, ErrInvalidLengthMessage
|
||||
}
|
||||
iNdEx += length
|
||||
case 3:
|
||||
depth++
|
||||
case 4:
|
||||
if depth == 0 {
|
||||
return 0, ErrUnexpectedEndOfGroupMessage
|
||||
if iNdEx < 0 {
|
||||
return 0, ErrInvalidLengthMessage
|
||||
}
|
||||
depth--
|
||||
return iNdEx, nil
|
||||
case 3:
|
||||
for {
|
||||
var innerWire uint64
|
||||
var start int = iNdEx
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowMessage
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
innerWire |= (uint64(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
innerWireType := int(innerWire & 0x7)
|
||||
if innerWireType == 4 {
|
||||
break
|
||||
}
|
||||
next, err := skipMessage(dAtA[start:])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
iNdEx = start + next
|
||||
if iNdEx < 0 {
|
||||
return 0, ErrInvalidLengthMessage
|
||||
}
|
||||
}
|
||||
return iNdEx, nil
|
||||
case 4:
|
||||
return iNdEx, nil
|
||||
case 5:
|
||||
iNdEx += 4
|
||||
return iNdEx, nil
|
||||
default:
|
||||
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
|
||||
}
|
||||
if iNdEx < 0 {
|
||||
return 0, ErrInvalidLengthMessage
|
||||
}
|
||||
if depth == 0 {
|
||||
return iNdEx, nil
|
||||
}
|
||||
}
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
var (
|
||||
ErrInvalidLengthMessage = fmt.Errorf("proto: negative length found during unmarshaling")
|
||||
ErrIntOverflowMessage = fmt.Errorf("proto: integer overflow")
|
||||
ErrUnexpectedEndOfGroupMessage = fmt.Errorf("proto: unexpected end of group")
|
||||
ErrInvalidLengthMessage = fmt.Errorf("proto: negative length found during unmarshaling")
|
||||
ErrIntOverflowMessage = fmt.Errorf("proto: integer overflow")
|
||||
)
|
||||
|
|
|
@ -16,6 +16,6 @@ message RaftMessage {
|
|||
}
|
||||
|
||||
message Ready {
|
||||
repeated bytes txHashes = 1 [(gogoproto.customtype) = "github.com/meshplus/bitxhub-kit/types.Hash", (gogoproto.nullable) = false];
|
||||
repeated bytes txHashes = 1 [(gogoproto.customtype) = "github.com/meshplus/bitxhub-kit/types.Hash"];
|
||||
uint64 height = 2;
|
||||
}
|
|
@ -166,7 +166,7 @@ func (mpi *mempoolImpl) processTransactions(txs []*pb.Transaction) error {
|
|||
continue
|
||||
}
|
||||
// check the existence of hash of this tx
|
||||
txHash := tx.TransactionHash.Hex()
|
||||
txHash := tx.TransactionHash.String()
|
||||
if txPointer := mpi.txStore.txHashMap[txHash]; txPointer != nil {
|
||||
mpi.logger.Warningf("Tx %s already received", txHash)
|
||||
continue
|
||||
|
@ -208,7 +208,7 @@ func (txStore *transactionStore) InsertTxs(txs map[string][]*pb.Transaction) map
|
|||
dirtyAccounts := make(map[string]bool)
|
||||
for account, list := range txs {
|
||||
for _, tx := range list {
|
||||
txHash := tx.TransactionHash.Hex()
|
||||
txHash := tx.TransactionHash.String()
|
||||
txPointer := &orderedIndexKey{
|
||||
account: account,
|
||||
nonce: tx.Nonce,
|
||||
|
@ -296,7 +296,7 @@ func (mpi *mempoolImpl) generateBlock(isTimeout bool) (*raftproto.Ready, error)
|
|||
txList := make([]*pb.Transaction, len(result))
|
||||
for i, v := range result {
|
||||
rawTransaction := mpi.txStore.getTxByOrderKey(v.account, v.nonce)
|
||||
hashList[i] = rawTransaction.TransactionHash
|
||||
hashList[i] = *rawTransaction.TransactionHash
|
||||
txList[i] = rawTransaction
|
||||
}
|
||||
mpi.increaseBatchSeqNo()
|
||||
|
@ -327,7 +327,7 @@ func (mpi *mempoolImpl) getBlock(ready *raftproto.Ready) *mempoolBatch {
|
|||
mpi.logger.Warningf("Leader get block failed, can't find block %d from batchedCache", ready.Height)
|
||||
missingTxnHashList := make(map[uint64]string)
|
||||
for i, txHash := range ready.TxHashes {
|
||||
missingTxnHashList[uint64(i)] = txHash.Hex()
|
||||
missingTxnHashList[uint64(i)] = txHash.String()
|
||||
}
|
||||
res.missingTxnHashList = missingTxnHashList
|
||||
} else {
|
||||
|
@ -358,18 +358,19 @@ func (mpi *mempoolImpl) constructSameBatch(ready *raftproto.Ready) *mempoolBatch
|
|||
txItem *txItem
|
||||
ok bool
|
||||
)
|
||||
if txPointer, _ = mpi.txStore.txHashMap[txHash.Hex()]; txPointer == nil {
|
||||
missingTxList[uint64(index)] = txHash.Hex()
|
||||
strHash := txHash.String()
|
||||
if txPointer, _ = mpi.txStore.txHashMap[strHash]; txPointer == nil {
|
||||
missingTxList[uint64(index)] = strHash
|
||||
continue
|
||||
}
|
||||
if txMap, ok = mpi.txStore.allTxs[txPointer.account]; !ok {
|
||||
mpi.logger.Warningf("Transaction %s exist in txHashMap but not in allTxs", txHash.Hex())
|
||||
missingTxList[uint64(index)] = txHash.Hex()
|
||||
mpi.logger.Warningf("Transaction %s exist in txHashMap but not in allTxs", strHash)
|
||||
missingTxList[uint64(index)] = strHash
|
||||
continue
|
||||
}
|
||||
if txItem, ok = txMap.items[txPointer.nonce]; !ok {
|
||||
mpi.logger.Warningf("Transaction %s exist in txHashMap but not in allTxs", txHash.Hex())
|
||||
missingTxList[uint64(index)] = txHash.Hex()
|
||||
mpi.logger.Warningf("Transaction %s exist in txHashMap but not in allTxs", strHash)
|
||||
missingTxList[uint64(index)] = strHash
|
||||
continue
|
||||
}
|
||||
txList = append(txList, txItem.tx)
|
||||
|
@ -390,11 +391,11 @@ func (mpi *mempoolImpl) processCommitTransactions(ready *raftproto.Ready) {
|
|||
dirtyAccounts := make(map[string]bool)
|
||||
// update current cached commit nonce for account
|
||||
for _, txHash := range ready.TxHashes {
|
||||
txHashStr := txHash.Hex()
|
||||
txPointer := mpi.txStore.txHashMap[txHashStr]
|
||||
txPointer, ok := mpi.txStore.txHashMap[txHashStr]
|
||||
strHash := txHash.String()
|
||||
txPointer := mpi.txStore.txHashMap[strHash]
|
||||
txPointer, ok := mpi.txStore.txHashMap[strHash]
|
||||
if !ok {
|
||||
mpi.logger.Warningf("Remove transaction %s failed, Can't find it from txHashMap", txHashStr)
|
||||
mpi.logger.Warningf("Remove transaction %s failed, Can't find it from txHashMap", strHash)
|
||||
continue
|
||||
}
|
||||
preCommitNonce := mpi.txStore.nonceCache.getCommitNonce(txPointer.account)
|
||||
|
@ -402,7 +403,7 @@ func (mpi *mempoolImpl) processCommitTransactions(ready *raftproto.Ready) {
|
|||
if preCommitNonce < newCommitNonce {
|
||||
mpi.txStore.nonceCache.setCommitNonce(txPointer.account, newCommitNonce)
|
||||
}
|
||||
delete(mpi.txStore.txHashMap, txHashStr)
|
||||
delete(mpi.txStore.txHashMap, strHash)
|
||||
delete(mpi.txStore.batchedTxs, *txPointer)
|
||||
dirtyAccounts[txPointer.account] = true
|
||||
}
|
||||
|
@ -508,7 +509,7 @@ func (mpi *mempoolImpl) loadTxnFromCache(fetchTxnRequest *FetchTxnRequest) (map[
|
|||
targetBatchLen := uint64(len(targetBatch))
|
||||
txList := make(map[uint64]*pb.Transaction, len(missingHashList))
|
||||
for index, txHash := range missingHashList {
|
||||
if index > targetBatchLen || targetBatch[index].TransactionHash.Hex() != txHash {
|
||||
if index > targetBatchLen || targetBatch[index].TransactionHash.String() != txHash {
|
||||
return nil, fmt.Errorf("find invaild transaction, index: %d, targetHash: %s", index, txHash)
|
||||
}
|
||||
txList[index] = targetBatch[index]
|
||||
|
@ -523,11 +524,11 @@ func (mpi *mempoolImpl) loadTxnFromStorage(fetchTxnRequest *FetchTxnRequest) (ma
|
|||
for index, txHash := range missingHashList {
|
||||
var (
|
||||
tx *pb.Transaction
|
||||
rawHash types.Hash
|
||||
rawHash []byte
|
||||
err error
|
||||
ok bool
|
||||
)
|
||||
if rawHash, err = hex2Hash(txHash); err != nil {
|
||||
if rawHash, err = types.HexDecodeString(txHash); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if tx, ok = mpi.load(rawHash); !ok {
|
||||
|
@ -545,13 +546,13 @@ func (mpi *mempoolImpl) loadTxnFromLedger(fetchTxnRequest *FetchTxnRequest) (map
|
|||
for index, txHash := range missingHashList {
|
||||
var (
|
||||
tx *pb.Transaction
|
||||
rawHash types.Hash
|
||||
err error
|
||||
)
|
||||
if rawHash, err = hex2Hash(txHash); err != nil {
|
||||
return nil, err
|
||||
hash := types.NewHashByStr(txHash)
|
||||
if hash == nil {
|
||||
return nil, errors.New("nil hash")
|
||||
}
|
||||
if tx, err = mpi.ledgerHelper(rawHash); err != nil {
|
||||
if tx, err = mpi.ledgerHelper(*hash); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
txList[index] = tx
|
||||
|
@ -572,7 +573,7 @@ func (mpi *mempoolImpl) processFetchTxnResponse(fetchTxnResponse *FetchTxnRespon
|
|||
validTxn := make([]*pb.Transaction, 0)
|
||||
targetBatch := mpi.txStore.missingBatch[fetchTxnResponse.Height]
|
||||
for index, tx := range fetchTxnResponse.MissingTxnList {
|
||||
if tx.Hash().Hex() != targetBatch[index] {
|
||||
if tx.TransactionHash.String() != targetBatch[index] {
|
||||
return errors.New("find a hash mismatch tx")
|
||||
}
|
||||
validTxn = append(validTxn, tx)
|
||||
|
|
|
@ -30,12 +30,12 @@ func TestProcessTransactions(t *testing.T) {
|
|||
ast.Equal(1, mpi.txStore.parkingLotIndex.size())
|
||||
ast.Equal(5, len(mpi.txStore.txHashMap))
|
||||
ast.Equal(0, len(mpi.txStore.batchedCache))
|
||||
ast.Equal(2, mpi.txStore.allTxs[account1.Hex()].index.size())
|
||||
ast.Equal(3, mpi.txStore.allTxs[account2.Hex()].index.size())
|
||||
ast.Equal(uint64(1), mpi.txStore.nonceCache.getCommitNonce(account1.Hex()))
|
||||
ast.Equal(uint64(3), mpi.txStore.nonceCache.getPendingNonce(account1.Hex()))
|
||||
ast.Equal(uint64(1), mpi.txStore.nonceCache.getCommitNonce(account2.Hex()))
|
||||
ast.Equal(uint64(3), mpi.txStore.nonceCache.getPendingNonce(account2.Hex()))
|
||||
ast.Equal(2, mpi.txStore.allTxs[account1.String()].index.size())
|
||||
ast.Equal(3, mpi.txStore.allTxs[account2.String()].index.size())
|
||||
ast.Equal(uint64(1), mpi.txStore.nonceCache.getCommitNonce(account1.String()))
|
||||
ast.Equal(uint64(3), mpi.txStore.nonceCache.getPendingNonce(account1.String()))
|
||||
ast.Equal(uint64(1), mpi.txStore.nonceCache.getCommitNonce(account2.String()))
|
||||
ast.Equal(uint64(3), mpi.txStore.nonceCache.getPendingNonce(account2.String()))
|
||||
|
||||
go func() {
|
||||
mpi.batchSize = 4
|
||||
|
@ -57,10 +57,10 @@ func TestProcessTransactions(t *testing.T) {
|
|||
ast.Equal(7, len(mpi.txStore.txHashMap))
|
||||
ast.Equal(1, len(mpi.txStore.batchedCache))
|
||||
ast.Equal(4, len(mpi.txStore.batchedCache[uint64(2)]))
|
||||
ast.Equal(3, mpi.txStore.allTxs[account1.Hex()].index.size())
|
||||
ast.Equal(4, mpi.txStore.allTxs[account2.Hex()].index.size())
|
||||
ast.Equal(uint64(4), mpi.txStore.nonceCache.getPendingNonce(account1.Hex()))
|
||||
ast.Equal(uint64(3), mpi.txStore.nonceCache.getPendingNonce(account2.Hex()))
|
||||
ast.Equal(3, mpi.txStore.allTxs[account1.String()].index.size())
|
||||
ast.Equal(4, mpi.txStore.allTxs[account2.String()].index.size())
|
||||
ast.Equal(uint64(4), mpi.txStore.nonceCache.getPendingNonce(account1.String()))
|
||||
ast.Equal(uint64(3), mpi.txStore.nonceCache.getPendingNonce(account2.String()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ func TestProcessFetchTxnRequest(t *testing.T) {
|
|||
txList = append(txList, tx1)
|
||||
|
||||
missingList := make(map[uint64]string)
|
||||
missingList[0] = tx1.TransactionHash.Hex()
|
||||
missingList[0] = tx1.TransactionHash.String()
|
||||
fetchTxnRequest := &FetchTxnRequest{
|
||||
Height: uint64(2),
|
||||
MissingTxHashes: missingList,
|
||||
|
@ -105,7 +105,7 @@ func TestProcessFetchTxnResponse(t *testing.T) {
|
|||
privKey1 := genPrivKey()
|
||||
tx1 := constructTx(uint64(1), &privKey1)
|
||||
missingList := make(map[uint64]string)
|
||||
missingList[0] = tx1.TransactionHash.Hex()
|
||||
missingList[0] = tx1.TransactionHash.String()
|
||||
mpi.txStore.missingBatch[uint64(2)] = missingList
|
||||
|
||||
fetchTxnResponse.MissingTxnList = make(map[uint64]*pb.Transaction)
|
||||
|
|
|
@ -104,7 +104,7 @@ func TestGetBlock(t *testing.T) {
|
|||
var txList []*pb.Transaction
|
||||
var txHashList []types.Hash
|
||||
txList = append(txList, tx1, tx2, tx3, tx4)
|
||||
txHashList = append(txHashList, tx1.TransactionHash, tx2.TransactionHash, tx3.TransactionHash, tx5.TransactionHash)
|
||||
txHashList = append(txHashList, *tx1.TransactionHash, *tx2.TransactionHash, *tx3.TransactionHash, *tx5.TransactionHash)
|
||||
err = mpi.processTransactions(txList)
|
||||
ast.Nil(err)
|
||||
ready := &raftproto.Ready{
|
||||
|
@ -146,7 +146,7 @@ func TestGetPendingNonceByAccount(t *testing.T) {
|
|||
|
||||
privKey1 := genPrivKey()
|
||||
account1, _ := privKey1.PublicKey().Address()
|
||||
nonce := mpi.GetPendingNonceByAccount(account1.Hex())
|
||||
nonce := mpi.GetPendingNonceByAccount(account1.String())
|
||||
ast.Equal(uint64(1), nonce)
|
||||
|
||||
privKey2 := genPrivKey()
|
||||
|
@ -160,9 +160,9 @@ func TestGetPendingNonceByAccount(t *testing.T) {
|
|||
txList = append(txList, tx1, tx2, tx3, tx4, tx5)
|
||||
err = mpi.processTransactions(txList)
|
||||
ast.Nil(err)
|
||||
nonce = mpi.GetPendingNonceByAccount(account1.Hex())
|
||||
nonce = mpi.GetPendingNonceByAccount(account1.String())
|
||||
ast.Equal(uint64(3), nonce)
|
||||
nonce = mpi.GetPendingNonceByAccount(account2.Hex())
|
||||
nonce = mpi.GetPendingNonceByAccount(account2.String())
|
||||
ast.Equal(uint64(3), nonce, "not 4")
|
||||
}
|
||||
|
||||
|
@ -175,7 +175,7 @@ func TestCommitTransactions(t *testing.T) {
|
|||
|
||||
privKey1 := genPrivKey()
|
||||
account1, _ := privKey1.PublicKey().Address()
|
||||
nonce := mpi.GetPendingNonceByAccount(account1.Hex())
|
||||
nonce := mpi.GetPendingNonceByAccount(account1.String())
|
||||
ast.Equal(uint64(1), nonce)
|
||||
|
||||
privKey2 := genPrivKey()
|
||||
|
@ -205,7 +205,7 @@ func TestCommitTransactions(t *testing.T) {
|
|||
ast.Equal(uint64(2), height)
|
||||
|
||||
var txHashList []types.Hash
|
||||
txHashList = append(txHashList, tx1.TransactionHash, tx2.TransactionHash, tx3.TransactionHash, tx5.TransactionHash)
|
||||
txHashList = append(txHashList, *tx1.TransactionHash, *tx2.TransactionHash, *tx3.TransactionHash, *tx5.TransactionHash)
|
||||
ready := &raftproto.Ready{
|
||||
Height: uint64(2),
|
||||
TxHashes: txHashList,
|
||||
|
|
|
@ -22,7 +22,7 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
InterchainContractAddr = types.String2Address("000000000000000000000000000000000000000a")
|
||||
InterchainContractAddr = types.NewAddressByStr("000000000000000000000000000000000000000a")
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -81,9 +81,14 @@ func constructIBTPTx(nonce uint64, privKey *crypto.PrivateKey) *pb.Transaction {
|
|||
privK = *privKey
|
||||
pubKey := privK.PublicKey()
|
||||
from, _ := pubKey.Address()
|
||||
to := from.Hex()
|
||||
ibtp := mockIBTP(from.Hex(), to, nonce)
|
||||
tx := mockInterChainTx(ibtp)
|
||||
to := from.String()
|
||||
ibtp := mockIBTP(from.String(), to, nonce)
|
||||
tx := &pb.Transaction{
|
||||
To: InterchainContractAddr,
|
||||
Nonce: ibtp.Index,
|
||||
IBTP: ibtp,
|
||||
Extra: []byte(fmt.Sprintf("%s-%s-%d", ibtp.From, ibtp.To, ibtp.Type)),
|
||||
}
|
||||
tx.Timestamp = time.Now().UnixNano()
|
||||
sig, _ := privK.Sign(tx.SignHash().Bytes())
|
||||
tx.Signature = sig
|
||||
|
@ -99,26 +104,6 @@ func cleanTestData() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func mockInterChainTx(ibtp *pb.IBTP) *pb.Transaction {
|
||||
ib, _ := ibtp.Marshal()
|
||||
ipd := &pb.InvokePayload{
|
||||
Method: "HandleIBTP",
|
||||
Args: []*pb.Arg{{Value: ib}},
|
||||
}
|
||||
pd, _ := ipd.Marshal()
|
||||
data := &pb.TransactionData{
|
||||
VmType: pb.TransactionData_BVM,
|
||||
Type: pb.TransactionData_INVOKE,
|
||||
Payload: pd,
|
||||
}
|
||||
return &pb.Transaction{
|
||||
To: InterchainContractAddr,
|
||||
Nonce: ibtp.Index,
|
||||
Data: data,
|
||||
Extra: []byte(fmt.Sprintf("%s-%s-%d", ibtp.From, ibtp.To, ibtp.Type)),
|
||||
}
|
||||
}
|
||||
|
||||
func mockIBTP(from, to string, nonce uint64) *pb.IBTP {
|
||||
content := pb.Content{
|
||||
SrcContractId: from,
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
pb "github.com/meshplus/bitxhub-model/pb"
|
||||
io "io"
|
||||
math "math"
|
||||
math_bits "math/bits"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
|
@ -21,7 +20,7 @@ var _ = math.Inf
|
|||
// is compatible with the proto package it is being compiled against.
|
||||
// A compilation error at this line likely means your copy of the
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
|
||||
const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package
|
||||
|
||||
type TxSlice struct {
|
||||
TxList []*pb.Transaction `protobuf:"bytes,1,rep,name=TxList,proto3" json:"TxList,omitempty"`
|
||||
|
@ -41,7 +40,7 @@ func (m *TxSlice) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
|||
return xxx_messageInfo_TxSlice.Marshal(b, m, deterministic)
|
||||
} else {
|
||||
b = b[:cap(b)]
|
||||
n, err := m.MarshalToSizedBuffer(b)
|
||||
n, err := m.MarshalTo(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -87,7 +86,7 @@ func (m *FetchTxnRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, err
|
|||
return xxx_messageInfo_FetchTxnRequest.Marshal(b, m, deterministic)
|
||||
} else {
|
||||
b = b[:cap(b)]
|
||||
n, err := m.MarshalToSizedBuffer(b)
|
||||
n, err := m.MarshalTo(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -147,7 +146,7 @@ func (m *FetchTxnResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, er
|
|||
return xxx_messageInfo_FetchTxnResponse.Marshal(b, m, deterministic)
|
||||
} else {
|
||||
b = b[:cap(b)]
|
||||
n, err := m.MarshalToSizedBuffer(b)
|
||||
n, err := m.MarshalTo(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -228,7 +227,7 @@ var fileDescriptor_33c57e4bae7b9afd = []byte{
|
|||
func (m *TxSlice) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||
n, err := m.MarshalTo(dAtA)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -236,36 +235,29 @@ func (m *TxSlice) Marshal() (dAtA []byte, err error) {
|
|||
}
|
||||
|
||||
func (m *TxSlice) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *TxSlice) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
var i int
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.TxList) > 0 {
|
||||
for iNdEx := len(m.TxList) - 1; iNdEx >= 0; iNdEx-- {
|
||||
{
|
||||
size, err := m.TxList[iNdEx].MarshalToSizedBuffer(dAtA[:i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i -= size
|
||||
i = encodeVarintMessage(dAtA, i, uint64(size))
|
||||
}
|
||||
i--
|
||||
for _, msg := range m.TxList {
|
||||
dAtA[i] = 0xa
|
||||
i++
|
||||
i = encodeVarintMessage(dAtA, i, uint64(msg.Size()))
|
||||
n, err := msg.MarshalTo(dAtA[i:])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i += n
|
||||
}
|
||||
}
|
||||
return len(dAtA) - i, nil
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func (m *FetchTxnRequest) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||
n, err := m.MarshalTo(dAtA)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -273,49 +265,43 @@ func (m *FetchTxnRequest) Marshal() (dAtA []byte, err error) {
|
|||
}
|
||||
|
||||
func (m *FetchTxnRequest) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *FetchTxnRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
var i int
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.MissingTxHashes) > 0 {
|
||||
for k := range m.MissingTxHashes {
|
||||
v := m.MissingTxHashes[k]
|
||||
baseI := i
|
||||
i -= len(v)
|
||||
copy(dAtA[i:], v)
|
||||
i = encodeVarintMessage(dAtA, i, uint64(len(v)))
|
||||
i--
|
||||
dAtA[i] = 0x12
|
||||
i = encodeVarintMessage(dAtA, i, uint64(k))
|
||||
i--
|
||||
dAtA[i] = 0x8
|
||||
i = encodeVarintMessage(dAtA, i, uint64(baseI-i))
|
||||
i--
|
||||
dAtA[i] = 0x1a
|
||||
}
|
||||
if m.ReplicaId != 0 {
|
||||
dAtA[i] = 0x8
|
||||
i++
|
||||
i = encodeVarintMessage(dAtA, i, uint64(m.ReplicaId))
|
||||
}
|
||||
if m.Height != 0 {
|
||||
i = encodeVarintMessage(dAtA, i, uint64(m.Height))
|
||||
i--
|
||||
dAtA[i] = 0x10
|
||||
i++
|
||||
i = encodeVarintMessage(dAtA, i, uint64(m.Height))
|
||||
}
|
||||
if m.ReplicaId != 0 {
|
||||
i = encodeVarintMessage(dAtA, i, uint64(m.ReplicaId))
|
||||
i--
|
||||
dAtA[i] = 0x8
|
||||
if len(m.MissingTxHashes) > 0 {
|
||||
for k, _ := range m.MissingTxHashes {
|
||||
dAtA[i] = 0x1a
|
||||
i++
|
||||
v := m.MissingTxHashes[k]
|
||||
mapSize := 1 + sovMessage(uint64(k)) + 1 + len(v) + sovMessage(uint64(len(v)))
|
||||
i = encodeVarintMessage(dAtA, i, uint64(mapSize))
|
||||
dAtA[i] = 0x8
|
||||
i++
|
||||
i = encodeVarintMessage(dAtA, i, uint64(k))
|
||||
dAtA[i] = 0x12
|
||||
i++
|
||||
i = encodeVarintMessage(dAtA, i, uint64(len(v)))
|
||||
i += copy(dAtA[i:], v)
|
||||
}
|
||||
}
|
||||
return len(dAtA) - i, nil
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func (m *FetchTxnResponse) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||
n, err := m.MarshalTo(dAtA)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -323,62 +309,58 @@ func (m *FetchTxnResponse) Marshal() (dAtA []byte, err error) {
|
|||
}
|
||||
|
||||
func (m *FetchTxnResponse) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *FetchTxnResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
var i int
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.MissingTxnList) > 0 {
|
||||
for k := range m.MissingTxnList {
|
||||
v := m.MissingTxnList[k]
|
||||
baseI := i
|
||||
if v != nil {
|
||||
{
|
||||
size, err := v.MarshalToSizedBuffer(dAtA[:i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i -= size
|
||||
i = encodeVarintMessage(dAtA, i, uint64(size))
|
||||
}
|
||||
i--
|
||||
dAtA[i] = 0x12
|
||||
}
|
||||
i = encodeVarintMessage(dAtA, i, uint64(k))
|
||||
i--
|
||||
dAtA[i] = 0x8
|
||||
i = encodeVarintMessage(dAtA, i, uint64(baseI-i))
|
||||
i--
|
||||
dAtA[i] = 0x1a
|
||||
}
|
||||
if m.ReplicaId != 0 {
|
||||
dAtA[i] = 0x8
|
||||
i++
|
||||
i = encodeVarintMessage(dAtA, i, uint64(m.ReplicaId))
|
||||
}
|
||||
if m.Height != 0 {
|
||||
i = encodeVarintMessage(dAtA, i, uint64(m.Height))
|
||||
i--
|
||||
dAtA[i] = 0x10
|
||||
i++
|
||||
i = encodeVarintMessage(dAtA, i, uint64(m.Height))
|
||||
}
|
||||
if m.ReplicaId != 0 {
|
||||
i = encodeVarintMessage(dAtA, i, uint64(m.ReplicaId))
|
||||
i--
|
||||
dAtA[i] = 0x8
|
||||
if len(m.MissingTxnList) > 0 {
|
||||
for k, _ := range m.MissingTxnList {
|
||||
dAtA[i] = 0x1a
|
||||
i++
|
||||
v := m.MissingTxnList[k]
|
||||
msgSize := 0
|
||||
if v != nil {
|
||||
msgSize = v.Size()
|
||||
msgSize += 1 + sovMessage(uint64(msgSize))
|
||||
}
|
||||
mapSize := 1 + sovMessage(uint64(k)) + msgSize
|
||||
i = encodeVarintMessage(dAtA, i, uint64(mapSize))
|
||||
dAtA[i] = 0x8
|
||||
i++
|
||||
i = encodeVarintMessage(dAtA, i, uint64(k))
|
||||
if v != nil {
|
||||
dAtA[i] = 0x12
|
||||
i++
|
||||
i = encodeVarintMessage(dAtA, i, uint64(v.Size()))
|
||||
n1, err := v.MarshalTo(dAtA[i:])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i += n1
|
||||
}
|
||||
}
|
||||
}
|
||||
return len(dAtA) - i, nil
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func encodeVarintMessage(dAtA []byte, offset int, v uint64) int {
|
||||
offset -= sovMessage(v)
|
||||
base := offset
|
||||
for v >= 1<<7 {
|
||||
dAtA[offset] = uint8(v&0x7f | 0x80)
|
||||
v >>= 7
|
||||
offset++
|
||||
}
|
||||
dAtA[offset] = uint8(v)
|
||||
return base
|
||||
return offset + 1
|
||||
}
|
||||
func (m *TxSlice) Size() (n int) {
|
||||
if m == nil {
|
||||
|
@ -447,7 +429,14 @@ func (m *FetchTxnResponse) Size() (n int) {
|
|||
}
|
||||
|
||||
func sovMessage(x uint64) (n int) {
|
||||
return (math_bits.Len64(x|1) + 6) / 7
|
||||
for {
|
||||
n++
|
||||
x >>= 7
|
||||
if x == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
func sozMessage(x uint64) (n int) {
|
||||
return sovMessage(uint64((x << 1) ^ uint64((int64(x) >> 63))))
|
||||
|
@ -952,7 +941,6 @@ func (m *FetchTxnResponse) Unmarshal(dAtA []byte) error {
|
|||
func skipMessage(dAtA []byte) (n int, err error) {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
depth := 0
|
||||
for iNdEx < l {
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
|
@ -984,8 +972,10 @@ func skipMessage(dAtA []byte) (n int, err error) {
|
|||
break
|
||||
}
|
||||
}
|
||||
return iNdEx, nil
|
||||
case 1:
|
||||
iNdEx += 8
|
||||
return iNdEx, nil
|
||||
case 2:
|
||||
var length int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
|
@ -1006,30 +996,55 @@ func skipMessage(dAtA []byte) (n int, err error) {
|
|||
return 0, ErrInvalidLengthMessage
|
||||
}
|
||||
iNdEx += length
|
||||
case 3:
|
||||
depth++
|
||||
case 4:
|
||||
if depth == 0 {
|
||||
return 0, ErrUnexpectedEndOfGroupMessage
|
||||
if iNdEx < 0 {
|
||||
return 0, ErrInvalidLengthMessage
|
||||
}
|
||||
depth--
|
||||
return iNdEx, nil
|
||||
case 3:
|
||||
for {
|
||||
var innerWire uint64
|
||||
var start int = iNdEx
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowMessage
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
innerWire |= (uint64(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
innerWireType := int(innerWire & 0x7)
|
||||
if innerWireType == 4 {
|
||||
break
|
||||
}
|
||||
next, err := skipMessage(dAtA[start:])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
iNdEx = start + next
|
||||
if iNdEx < 0 {
|
||||
return 0, ErrInvalidLengthMessage
|
||||
}
|
||||
}
|
||||
return iNdEx, nil
|
||||
case 4:
|
||||
return iNdEx, nil
|
||||
case 5:
|
||||
iNdEx += 4
|
||||
return iNdEx, nil
|
||||
default:
|
||||
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
|
||||
}
|
||||
if iNdEx < 0 {
|
||||
return 0, ErrInvalidLengthMessage
|
||||
}
|
||||
if depth == 0 {
|
||||
return iNdEx, nil
|
||||
}
|
||||
}
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
var (
|
||||
ErrInvalidLengthMessage = fmt.Errorf("proto: negative length found during unmarshaling")
|
||||
ErrIntOverflowMessage = fmt.Errorf("proto: integer overflow")
|
||||
ErrUnexpectedEndOfGroupMessage = fmt.Errorf("proto: unexpected end of group")
|
||||
ErrInvalidLengthMessage = fmt.Errorf("proto: negative length found during unmarshaling")
|
||||
ErrIntOverflowMessage = fmt.Errorf("proto: integer overflow")
|
||||
)
|
||||
|
|
|
@ -28,8 +28,8 @@ func (mpi *mempoolImpl) batchDelete(hashes []types.Hash) {
|
|||
batch.Commit()
|
||||
}
|
||||
|
||||
func (mpi *mempoolImpl) load(hash types.Hash) (*pb.Transaction, bool) {
|
||||
txKey := compositeKey(hash.Bytes())
|
||||
func (mpi *mempoolImpl) load(hash []byte) (*pb.Transaction, bool) {
|
||||
txKey := compositeKey(hash)
|
||||
txData := mpi.storage.Get(txKey)
|
||||
if txData == nil {
|
||||
return nil, false
|
||||
|
|
|
@ -15,19 +15,19 @@ func TestStorage(t *testing.T) {
|
|||
|
||||
txList := make([]*pb.Transaction, 0)
|
||||
txHashList := make([]types.Hash, 0)
|
||||
txHash1, _ := hex2Hash("txHash1")
|
||||
txHash1 := types.NewHashByStr("txHash1")
|
||||
tx1 := &pb.Transaction{Nonce: uint64(1), TransactionHash: txHash1}
|
||||
txHash2, _ := hex2Hash("txHash2")
|
||||
txHash2 := types.NewHashByStr("txHash2")
|
||||
tx2 := &pb.Transaction{Nonce: uint64(1), TransactionHash: txHash2}
|
||||
txList = append(txList, tx1, tx2)
|
||||
txHashList = append(txHashList, txHash1, txHash2)
|
||||
txHashList = append(txHashList, *txHash1, *txHash1)
|
||||
mempool.batchStore(txList)
|
||||
tx, ok := mempool.load(txHash1)
|
||||
tx, ok := mempool.load(txHash1.Bytes())
|
||||
ast.Equal(true, ok)
|
||||
ast.Equal(uint64(1), tx.Nonce)
|
||||
|
||||
mempool.batchDelete(txHashList)
|
||||
tx, ok = mempool.load(txHash1)
|
||||
tx, ok = mempool.load(txHash1.Bytes())
|
||||
ast.Equal(false, ok)
|
||||
ast.Nil(tx)
|
||||
}
|
||||
|
|
|
@ -24,14 +24,14 @@ func TestForward(t *testing.T) {
|
|||
txList = append(txList, tx1, tx2, tx3, tx4, tx5)
|
||||
err := mpi.processTransactions(txList)
|
||||
ast.Nil(err)
|
||||
list := mpi.txStore.allTxs[account1.Hex()]
|
||||
list := mpi.txStore.allTxs[account1.String()]
|
||||
ast.Equal(5, list.index.size())
|
||||
ast.Equal(4, mpi.txStore.priorityIndex.size())
|
||||
ast.Equal(1, mpi.txStore.parkingLotIndex.size())
|
||||
|
||||
removeList := list.forward(uint64(3))
|
||||
ast.Equal(1, len(removeList))
|
||||
ast.Equal(2, len(removeList[account1.Hex()]))
|
||||
ast.Equal(uint64(1), removeList[account1.Hex()][0].Nonce)
|
||||
ast.Equal(uint64(2), removeList[account1.Hex()][1].Nonce)
|
||||
ast.Equal(2, len(removeList[account1.String()]))
|
||||
ast.Equal(uint64(1), removeList[account1.String()][0].Nonce)
|
||||
ast.Equal(uint64(2), removeList[account1.String()][1].Nonce)
|
||||
}
|
||||
|
|
|
@ -18,16 +18,11 @@ func TestGetAccount(t *testing.T) {
|
|||
ast.Nil(err)
|
||||
expectedAddr := fmt.Sprintf("%s-%s-%d", address, address, pb.IBTP_INTERCHAIN)
|
||||
ast.Equal(expectedAddr, addr)
|
||||
|
||||
data := &pb.TransactionData{
|
||||
Payload: []byte("test"),
|
||||
}
|
||||
tx = &pb.Transaction{
|
||||
To: InterchainContractAddr,
|
||||
Data: data,
|
||||
}
|
||||
_, err = getAccount(tx)
|
||||
ast.NotNil(err.Error(), "unmarshal invoke payload faile")
|
||||
ast.NotNil(err, "unmarshal invoke payload faile")
|
||||
}
|
||||
|
||||
func TestPoolIsFull(t *testing.T) {
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
package mempool
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/meshplus/bitxhub-kit/types"
|
||||
"github.com/meshplus/bitxhub-model/pb"
|
||||
"github.com/meshplus/bitxhub/internal/constant"
|
||||
raftproto "github.com/meshplus/bitxhub/pkg/order/etcdraft/proto"
|
||||
|
||||
cmap "github.com/orcaman/concurrent-map"
|
||||
|
@ -62,23 +58,6 @@ func newNonceCache() *nonceCache {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO (YH): refactor the tx struct
|
||||
func hex2Hash(hash string) (types.Hash, error) {
|
||||
var (
|
||||
hubHash types.Hash
|
||||
hashBytes []byte
|
||||
err error
|
||||
)
|
||||
if hashBytes, err = hex.DecodeString(hash); err != nil {
|
||||
return types.Hash{}, err
|
||||
}
|
||||
if len(hashBytes) != types.HashLength {
|
||||
return types.Hash{}, errors.New("invalid tx hash")
|
||||
}
|
||||
copy(hubHash[:], hashBytes)
|
||||
return hubHash, nil
|
||||
}
|
||||
|
||||
func (mpi *mempoolImpl) poolIsFull() bool {
|
||||
return atomic.LoadInt32(&mpi.txStore.poolSize) >= DefaultPoolSize
|
||||
}
|
||||
|
@ -126,20 +105,9 @@ func newTimer(d time.Duration) *timerManager {
|
|||
}
|
||||
|
||||
func getAccount(tx *pb.Transaction) (string, error) {
|
||||
if tx.To != constant.InterchainContractAddr.Address() {
|
||||
return tx.From.Hex(), nil
|
||||
}
|
||||
payload := &pb.InvokePayload{}
|
||||
if err := payload.Unmarshal(tx.Data.Payload); err != nil {
|
||||
return "", fmt.Errorf("unmarshal invoke payload failed: %s", err.Error())
|
||||
}
|
||||
if payload.Method == IBTPMethod1 || payload.Method == IBTPMethod2 {
|
||||
ibtp := &pb.IBTP{}
|
||||
if err := ibtp.Unmarshal(payload.Args[0].Value); err != nil {
|
||||
return "", fmt.Errorf("unmarshal ibtp from tx :%w", err)
|
||||
}
|
||||
account := fmt.Sprintf("%s-%s-%d", ibtp.From, ibtp.To, ibtp.Category())
|
||||
if tx.IBTP != nil {
|
||||
account := fmt.Sprintf("%s-%s-%d", tx.IBTP.From, tx.IBTP.To, tx.IBTP.Category())
|
||||
return account, nil
|
||||
}
|
||||
return tx.From.Hex(), nil
|
||||
return tx.From.String(), nil
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ func (n *Node) GetPendingNonceByAccount(account string) uint64 {
|
|||
func (n *Node) Prepare(tx *pb.Transaction) error {
|
||||
hash := tx.TransactionHash
|
||||
if ok := n.reqLookUp.LookUp(hash.Bytes()); ok {
|
||||
if tx, _ := n.getTransactionFunc(hash); tx != nil {
|
||||
if tx, _ := n.getTransactionFunc(*hash); tx != nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ func (n *Node) ReportState(height uint64, hash types.Hash) {
|
|||
if height%10 == 0 {
|
||||
n.logger.WithFields(logrus.Fields{
|
||||
"height": height,
|
||||
"hash": hash.ShortString(),
|
||||
"hash": hash.String(),
|
||||
}).Info("Report checkpoint")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,10 +43,7 @@ func TestNode_Start(t *testing.T) {
|
|||
|
||||
tx := &pb.Transaction{
|
||||
From: from,
|
||||
To: types.String2Address(to),
|
||||
Data: &pb.TransactionData{
|
||||
Amount: 10,
|
||||
},
|
||||
To: types.NewAddressByStr(to),
|
||||
Timestamp: time.Now().UnixNano(),
|
||||
Nonce: uint64(rand.Int63()),
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue