Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1802 from Bytom/prod
Browse files Browse the repository at this point in the history
Prod
  • Loading branch information
Paladz authored Oct 24, 2019
2 parents 43eb7d8 + b58e519 commit 19d90c0
Show file tree
Hide file tree
Showing 13 changed files with 206 additions and 85 deletions.
50 changes: 33 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,39 @@ $ ./bytomd node
available flags for `bytomd node`:

```
--auth.disable Disable rpc access authenticate
--chain_id string Select network type
-h, --help help for node
--mining Enable mining
--p2p.dial_timeout int Set dial timeout (default 3)
--p2p.handshake_timeout int Set handshake timeout (default 30)
--p2p.laddr string Node listen address.
--p2p.max_num_peers int Set max num peers (default 50)
--p2p.pex Enable Peer-Exchange (default true)
--p2p.seeds string Comma delimited host:port seed nodes
--p2p.skip_upnp Skip UPNP configuration
--prof_laddr string Use http to profile bytomd programs
--vault_mode Run in the offline enviroment
--wallet.disable Disable wallet
--wallet.rescan Rescan wallet
--web.closed Launch web browser or not
--simd.enable Enable the _simd_ feature to speed up the _PoW_ verification (e.g., during mining and block verification)
Flags:
--auth.disable Disable rpc access authenticate
--chain_id string Select network type
-h, --help help for node
--log_file string Log output file (default "log")
--log_level string Select log level(debug, info, warn, error or fatal)
--mining Enable mining
--p2p.dial_timeout int Set dial timeout (default 3)
--p2p.handshake_timeout int Set handshake timeout (default 30)
--p2p.keep_dial string Peers addresses try keeping connecting to, separated by ',' (for example "1.1.1.1:46657;2.2.2.2:46658")
--p2p.laddr string Node listen address. (0.0.0.0:0 means any interface, any port) (default "tcp://0.0.0.0:46656")
--p2p.lan_discoverable Whether the node can be discovered by nodes in the LAN (default true)
--p2p.max_num_peers int Set max num peers (default 50)
--p2p.node_key string Node key for p2p communication
--p2p.proxy_address string Connect via SOCKS5 proxy (eg. 127.0.0.1:1086)
--p2p.proxy_password string Password for proxy server
--p2p.proxy_username string Username for proxy server
--p2p.seeds string Comma delimited host:port seed nodes
--p2p.skip_upnp Skip UPNP configuration
--prof_laddr string Use http to profile bytomd programs
--simd.enable Enable SIMD mechan for tensority
--vault_mode Run in the offline enviroment
--wallet.disable Disable wallet
--wallet.rescan Rescan wallet
--wallet.txindex Save global tx index
--web.closed Lanch web browser or not
--ws.max_num_concurrent_reqs int Max number of concurrent websocket requests that may be processed concurrently (default 20)
--ws.max_num_websockets int Max number of websocket connections (default 25)
Global Flags:
--home string root directory for config and data
-r, --root string DEPRECATED. Use --home (default "/Users/zcc/Library/Application Support/Bytom")
--trace print out full stack trace on errors
```

Given the `bytomd` node is running, the general workflow is as follows:
Expand Down
15 changes: 4 additions & 11 deletions account/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ import (
"github.com/bytom/protocol/vm/vmutil"
)

var (
//chainTxUtxoNum maximum utxo quantity in a tx
chainTxUtxoNum = 5
//chainTxMergeGas chain tx gas
chainTxMergeGas = uint64(10000000)
)

//DecodeSpendAction unmarshal JSON-encoded data of spend action
func (m *Manager) DecodeSpendAction(data []byte) (txbuilder.Action, error) {
a := &spendAction{accounts: m}
Expand Down Expand Up @@ -66,8 +59,8 @@ func MergeSpendAction(actions []txbuilder.Action) []txbuilder.Action {
func calcMergeGas(num int) uint64 {
gas := uint64(0)
for num > 1 {
gas += chainTxMergeGas
num -= chainTxUtxoNum - 1
gas += txbuilder.ChainTxMergeGas
num -= txbuilder.ChainTxUtxoNum - 1
}
return gas
}
Expand Down Expand Up @@ -117,11 +110,11 @@ func (m *Manager) buildBtmTxChain(utxos []*UTXO, signer *signers.Signer) ([]*txb
}

buildAmount += input.Amount()
if builder.InputCount() != chainTxUtxoNum && index != len(utxos)-1 {
if builder.InputCount() != txbuilder.ChainTxUtxoNum && index != len(utxos)-1 {
continue
}

outAmount := buildAmount - chainTxMergeGas
outAmount := buildAmount - txbuilder.ChainTxMergeGas
output := types.NewTxOutput(*consensus.BTMAssetID, outAmount, acp.ControlProgram)
if err := builder.AddOutput(output); err != nil {
return nil, nil, err
Expand Down
46 changes: 23 additions & 23 deletions account/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import (
)

func TestReserveBtmUtxoChain(t *testing.T) {
chainTxUtxoNum = 3
txbuilder.ChainTxUtxoNum = 3
utxos := []*UTXO{}
m := mockAccountManager(t)
for i := uint64(1); i <= 20; i++ {
utxo := &UTXO{
OutputID: bc.Hash{V0: i},
AccountID: "TestAccountID",
AssetID: *consensus.BTMAssetID,
Amount: i * chainTxMergeGas,
Amount: i * txbuilder.ChainTxMergeGas,
}
utxos = append(utxos, utxo)

Expand All @@ -40,24 +40,24 @@ func TestReserveBtmUtxoChain(t *testing.T) {
err bool
}{
{
amount: 1 * chainTxMergeGas,
amount: 1 * txbuilder.ChainTxMergeGas,
want: []uint64{1},
},
{
amount: 888888 * chainTxMergeGas,
amount: 888888 * txbuilder.ChainTxMergeGas,
want: []uint64{},
err: true,
},
{
amount: 7 * chainTxMergeGas,
amount: 7 * txbuilder.ChainTxMergeGas,
want: []uint64{4, 3, 1},
},
{
amount: 15 * chainTxMergeGas,
amount: 15 * txbuilder.ChainTxMergeGas,
want: []uint64{5, 4, 3, 2, 1, 6},
},
{
amount: 163 * chainTxMergeGas,
amount: 163 * txbuilder.ChainTxMergeGas,
want: []uint64{20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 2, 1, 3},
},
}
Expand All @@ -72,7 +72,7 @@ func TestReserveBtmUtxoChain(t *testing.T) {

got := []uint64{}
for _, utxo := range utxos {
got = append(got, utxo.Amount/chainTxMergeGas)
got = append(got, utxo.Amount/txbuilder.ChainTxMergeGas)
}

if !testutil.DeepEqual(got, c.want) {
Expand All @@ -83,7 +83,7 @@ func TestReserveBtmUtxoChain(t *testing.T) {
}

func TestBuildBtmTxChain(t *testing.T) {
chainTxUtxoNum = 3
txbuilder.ChainTxUtxoNum = 3
m := mockAccountManager(t)
cases := []struct {
inputUtxo []uint64
Expand All @@ -95,7 +95,7 @@ func TestBuildBtmTxChain(t *testing.T) {
inputUtxo: []uint64{5},
wantInput: [][]uint64{},
wantOutput: [][]uint64{},
wantUtxo: 5 * chainTxMergeGas,
wantUtxo: 5 * txbuilder.ChainTxMergeGas,
},
{
inputUtxo: []uint64{5, 4},
Expand All @@ -105,7 +105,7 @@ func TestBuildBtmTxChain(t *testing.T) {
wantOutput: [][]uint64{
[]uint64{8},
},
wantUtxo: 8 * chainTxMergeGas,
wantUtxo: 8 * txbuilder.ChainTxMergeGas,
},
{
inputUtxo: []uint64{5, 4, 1, 1},
Expand All @@ -117,7 +117,7 @@ func TestBuildBtmTxChain(t *testing.T) {
[]uint64{9},
[]uint64{9},
},
wantUtxo: 9 * chainTxMergeGas,
wantUtxo: 9 * txbuilder.ChainTxMergeGas,
},
{
inputUtxo: []uint64{22, 123, 53, 234, 23, 4, 2423, 24, 23, 43, 34, 234, 234, 24},
Expand All @@ -139,7 +139,7 @@ func TestBuildBtmTxChain(t *testing.T) {
[]uint64{3038},
[]uint64{3491},
},
wantUtxo: 3491 * chainTxMergeGas,
wantUtxo: 3491 * txbuilder.ChainTxMergeGas,
},
}

Expand All @@ -157,7 +157,7 @@ func TestBuildBtmTxChain(t *testing.T) {
utxos := []*UTXO{}
for _, amount := range c.inputUtxo {
utxos = append(utxos, &UTXO{
Amount: amount * chainTxMergeGas,
Amount: amount * txbuilder.ChainTxMergeGas,
AssetID: *consensus.BTMAssetID,
Address: acp.Address,
ControlProgram: acp.ControlProgram,
Expand All @@ -172,12 +172,12 @@ func TestBuildBtmTxChain(t *testing.T) {
for i, tpl := range tpls {
gotInput := []uint64{}
for _, input := range tpl.Transaction.Inputs {
gotInput = append(gotInput, input.Amount()/chainTxMergeGas)
gotInput = append(gotInput, input.Amount()/txbuilder.ChainTxMergeGas)
}

gotOutput := []uint64{}
for _, output := range tpl.Transaction.Outputs {
gotOutput = append(gotOutput, output.Amount/chainTxMergeGas)
gotOutput = append(gotOutput, output.Amount/txbuilder.ChainTxMergeGas)
}

if !testutil.DeepEqual(c.wantInput[i], gotInput) {
Expand Down Expand Up @@ -540,7 +540,7 @@ func TestMergeSpendAction(t *testing.T) {
}

func TestCalcMergeGas(t *testing.T) {
chainTxUtxoNum = 10
txbuilder.ChainTxUtxoNum = 10
cases := []struct {
utxoNum int
gas uint64
Expand All @@ -555,27 +555,27 @@ func TestCalcMergeGas(t *testing.T) {
},
{
utxoNum: 9,
gas: chainTxMergeGas,
gas: txbuilder.ChainTxMergeGas,
},
{
utxoNum: 10,
gas: chainTxMergeGas,
gas: txbuilder.ChainTxMergeGas,
},
{
utxoNum: 11,
gas: chainTxMergeGas * 2,
gas: txbuilder.ChainTxMergeGas * 2,
},
{
utxoNum: 20,
gas: chainTxMergeGas * 3,
gas: txbuilder.ChainTxMergeGas * 3,
},
{
utxoNum: 21,
gas: chainTxMergeGas * 3,
gas: txbuilder.ChainTxMergeGas * 3,
},
{
utxoNum: 74,
gas: chainTxMergeGas * 9,
gas: txbuilder.ChainTxMergeGas * 9,
},
}

Expand Down
1 change: 1 addition & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ func (a *API) buildHandler() {
m.Handle("/submit-transaction", jsonHandler(a.submit))
m.Handle("/submit-transactions", jsonHandler(a.submitTxs))
m.Handle("/estimate-transaction-gas", jsonHandler(a.estimateTxGas))
m.Handle("/estimate-chain-transaction-gas", jsonHandler(a.estimateChainTxGas))

m.Handle("/get-unconfirmed-transaction", jsonHandler(a.getUnconfirmedTx))
m.Handle("/list-unconfirmed-transactions", jsonHandler(a.listUnconfirmedTxs))
Expand Down
13 changes: 13 additions & 0 deletions api/transact.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,5 +226,18 @@ func (a *API) estimateTxGas(ctx context.Context, in struct {
if err != nil {
return NewErrorResponse(err)
}

return NewSuccessResponse(txGasResp)
}

// POST /estimate-chain-transaction-gas
func (a *API) estimateChainTxGas(ctx context.Context, in struct {
TxTemplates []txbuilder.Template `json:"transaction_templates"`
}) Response {
txGasResp, err := txbuilder.EstimateChainTxGas(in.TxTemplates)
if err != nil {
return NewErrorResponse(err)
}

return NewSuccessResponse(txGasResp)
}
29 changes: 26 additions & 3 deletions blockchain/txbuilder/estimate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,43 @@ import (
"github.com/bytom/protocol/vm/vmutil"
)

const (
baseSize = int64(176) // inputSize(112) + outputSize(64)
baseP2WPKHSize = int64(98)
baseP2WPKHGas = int64(1409)
)

var (
//ChainTxUtxoNum maximum utxo quantity in a tx
ChainTxUtxoNum = 5
//ChainTxMergeGas chain tx gas
ChainTxMergeGas = uint64(6000000)
)

// EstimateTxGasInfo estimate transaction consumed gas
type EstimateTxGasInfo struct {
TotalNeu int64 `json:"total_neu"`
FlexibleNeu int64 `json:"flexible_neu"`
StorageNeu int64 `json:"storage_neu"`
VMNeu int64 `json:"vm_neu"`
ChainTxNeu int64 `json:"chain_tx_neu"`
}

func EstimateChainTxGas(templates []Template) (*EstimateTxGasInfo, error) {
estimated, err := EstimateTxGas(templates[len(templates)-1])
if err != nil {
return nil, err
}

if len(templates) > 1 {
estimated.ChainTxNeu = int64(ChainTxMergeGas) * int64(len(templates)-1)
}
return estimated, nil
}

// EstimateTxGas estimate consumed neu for transaction
func EstimateTxGas(template Template) (*EstimateTxGasInfo, error) {
var baseP2WSHSize, totalWitnessSize, baseP2WSHGas, totalP2WPKHGas, totalP2WSHGas, totalIssueGas int64
baseSize := int64(176) // inputSize(112) + outputSize(64)
baseP2WPKHSize := int64(98)
baseP2WPKHGas := int64(1409)
for pos, input := range template.Transaction.TxData.Inputs {
switch input.InputType() {
case types.SpendInputType:
Expand Down
2 changes: 2 additions & 0 deletions consensus/general.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ var MainNetParams = Params{
{240000, bc.NewHash([32]byte{0x35, 0x16, 0x65, 0x58, 0xf4, 0xef, 0x24, 0x82, 0x43, 0xbb, 0x15, 0x79, 0xd4, 0xfe, 0x1b, 0x14, 0x9f, 0xe9, 0xf0, 0xe0, 0x48, 0x72, 0x86, 0x68, 0xa7, 0xb9, 0xda, 0x58, 0x66, 0x3b, 0x1c, 0xcb})},
{270000, bc.NewHash([32]byte{0x9d, 0x6f, 0xcc, 0xd8, 0xb8, 0xe4, 0x8c, 0x17, 0x52, 0x9a, 0xe6, 0x1b, 0x40, 0x60, 0xe0, 0xe3, 0x6d, 0x1e, 0x89, 0xc0, 0x26, 0xdf, 0x1c, 0x28, 0x18, 0x0d, 0x29, 0x0c, 0x9b, 0x15, 0xcc, 0x97})},
{300000, bc.NewHash([32]byte{0xa2, 0x85, 0x84, 0x6c, 0xe0, 0x3e, 0x1d, 0x68, 0x98, 0x7d, 0x93, 0x21, 0xea, 0xcc, 0x1d, 0x07, 0x88, 0xd1, 0x4c, 0x77, 0xa3, 0xd7, 0x55, 0x8a, 0x2b, 0x4a, 0xf7, 0x4d, 0x50, 0x14, 0x53, 0x5d})},
{320000, bc.NewHash([32]byte{0xc6, 0xe7, 0x91, 0x6f, 0xcb, 0x7a, 0x42, 0x5d, 0xd6, 0x22, 0xef, 0x5d, 0x6a, 0x5c, 0xc1, 0x91, 0xa9, 0xd9, 0x06, 0x44, 0xcf, 0x36, 0x43, 0x55, 0xfe, 0x45, 0xaf, 0x24, 0x07, 0x31, 0x23, 0xc6})},
},
}

Expand All @@ -156,6 +157,7 @@ var TestNetParams = Params{
{93000, bc.NewHash([32]byte{0x6f, 0x4f, 0x37, 0x5f, 0xe9, 0xfb, 0xdf, 0x66, 0x60, 0x0e, 0xf0, 0x39, 0xb7, 0x18, 0x26, 0x75, 0xa0, 0x9a, 0xa5, 0x9b, 0x83, 0xc9, 0x9a, 0x25, 0x45, 0xb8, 0x7d, 0xd4, 0x99, 0x24, 0xa2, 0x8a})},
{113300, bc.NewHash([32]byte{0x7a, 0x69, 0x75, 0xa5, 0xf6, 0xb6, 0x94, 0xf3, 0x94, 0xa2, 0x63, 0x91, 0x28, 0xb6, 0xab, 0x7e, 0xf9, 0x71, 0x27, 0x5a, 0xe2, 0x59, 0xd3, 0xff, 0x70, 0x6e, 0xcb, 0xd8, 0xd8, 0x30, 0x9c, 0xc4})},
{235157, bc.NewHash([32]byte{0xfa, 0x76, 0x36, 0x3e, 0x9e, 0x58, 0xea, 0xe4, 0x7d, 0x26, 0x70, 0x7e, 0xf3, 0x8b, 0xfd, 0xad, 0x1a, 0x99, 0xf7, 0x4c, 0xac, 0xc6, 0x80, 0x99, 0x58, 0x10, 0x13, 0x66, 0x4b, 0x8c, 0x39, 0x4f})},
{252383, bc.NewHash([32]byte{0xa1, 0xaa, 0xe6, 0xd9, 0x42, 0x94, 0x99, 0x7b, 0x9b, 0x71, 0x5b, 0xf5, 0x23, 0x9a, 0xee, 0x92, 0x27, 0x84, 0x4c, 0x32, 0x47, 0xf2, 0xf2, 0xd9, 0xe3, 0xd7, 0x6a, 0x2b, 0xbe, 0xc3, 0x1f, 0x50})},
},
}

Expand Down
6 changes: 3 additions & 3 deletions dashboard/dashboard/dashboard.go

Large diffs are not rendered by default.

Loading

0 comments on commit 19d90c0

Please sign in to comment.