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 #1717 from Bytom/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Paladz authored Apr 19, 2019
2 parents 1eda55a + 82856be commit 8b73700
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 20 deletions.
7 changes: 4 additions & 3 deletions api/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,10 @@ func (a *API) listTransactions(ctx context.Context, filter struct {
transaction, err = a.wallet.GetTransactionByTxID(filter.ID)
if err != nil && filter.Unconfirmed {
transaction, err = a.wallet.GetUnconfirmedTxByTxID(filter.ID)
if err != nil {
return NewErrorResponse(err)
}
}

if err != nil {
return NewErrorResponse(err)
}
transactions = []*query.AnnotatedTx{transaction}
} else {
Expand Down
3 changes: 2 additions & 1 deletion asset/annotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ func Annotated(a *Asset) (*query.AnnotatedAsset, error) {
annotatedAsset := &query.AnnotatedAsset{
ID: a.AssetID,
Alias: *a.Alias,
VMVersion: a.VMVersion,
RawDefinitionByte: a.RawDefinitionByte,
Definition: &jsonDefinition,
IssuanceProgram: chainjson.HexBytes(a.IssuanceProgram),
}

annotatedAsset.LimitHeight, _ = vmutil.GetIssuanceProgramRestrictHeight(a.IssuanceProgram)
annotatedAsset.LimitHeight = vmutil.GetIssuanceProgramRestrictHeight(a.IssuanceProgram)
if a.Signer != nil {
annotatedAsset.AnnotatedSigner = query.AnnotatedSigner{
Type: a.Signer.Type,
Expand Down
2 changes: 1 addition & 1 deletion blockchain/txbuilder/estimate.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func EstimateTxGas(template Template) (*EstimateTxGasInfo, error) {

case types.IssuanceInputType:
issuanceProgram := input.IssuanceProgram()
if height, _ := vmutil.GetIssuanceProgramRestrictHeight(issuanceProgram); height > 0 {
if height := vmutil.GetIssuanceProgramRestrictHeight(issuanceProgram); height > 0 {
// the gas for issue program with checking block height
totalIssueGas += 5
}
Expand Down
1 change: 1 addition & 0 deletions cmd/bytomd/commands/run_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func init() {
runNodeCmd.Flags().String("p2p.seeds", config.P2P.Seeds, "Comma delimited host:port seed nodes")
runNodeCmd.Flags().String("p2p.node_key", config.P2P.PrivateKey, "Node key for p2p communication")
runNodeCmd.Flags().Bool("p2p.skip_upnp", config.P2P.SkipUPNP, "Skip UPNP configuration")
runNodeCmd.Flags().Bool("p2p.lan_discoverable", config.P2P.LANDiscover, "Whether the node can be discovered by nodes in the LAN")
runNodeCmd.Flags().Int("p2p.max_num_peers", config.P2P.MaxNumPeers, "Set max num peers")
runNodeCmd.Flags().Int("p2p.handshake_timeout", config.P2P.HandshakeTimeout, "Set handshake timeout")
runNodeCmd.Flags().Int("p2p.dial_timeout", config.P2P.DialTimeout, "Set dial timeout")
Expand Down
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ type P2PConfig struct {
PrivateKey string `mapstructure:"node_key"`
NodeKeyFile string `mapstructure:"node_key_file"`
SkipUPNP bool `mapstructure:"skip_upnp"`
LANDiscover bool `mapstructure:"lan_discoverable"`
MaxNumPeers int `mapstructure:"max_num_peers"`
HandshakeTimeout int `mapstructure:"handshake_timeout"`
DialTimeout int `mapstructure:"dial_timeout"`
Expand All @@ -164,6 +165,7 @@ func DefaultP2PConfig() *P2PConfig {
ListenAddress: "tcp://0.0.0.0:46656",
NodeKeyFile: "nodekey",
SkipUPNP: false,
LANDiscover: true,
MaxNumPeers: 50,
HandshakeTimeout: 30,
DialTimeout: 3,
Expand Down
2 changes: 1 addition & 1 deletion config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ seeds = "45.79.213.28:46657,198.74.61.131:46657,212.111.41.245:46657,47.100.214.
var testNetConfigTmpl = `chain_id = "wisdom"
[p2p]
laddr = "tcp://0.0.0.0:46656"
seeds = "52.83.107.224:46656,52.83.107.224:46656,52.83.251.197:46656"
seeds = "52.83.107.224:46656,52.83.251.197:46656"
`

var soloNetConfigTmpl = `chain_id = "solonet"
Expand Down
10 changes: 5 additions & 5 deletions dashboard/dashboard/dashboard.go

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions p2p/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ func NewSwitch(config *cfg.Config) (*Switch, error) {
if err != nil {
return nil, err
}

lanDiscv = mdns.NewLANDiscover(mdns.NewProtocol(), int(l.ExternalAddress().Port))
if config.P2P.LANDiscover {
lanDiscv = mdns.NewLANDiscover(mdns.NewProtocol(), int(l.ExternalAddress().Port))
}
}

return newSwitch(config, discv, lanDiscv, blacklistDB, l, privKey, listenAddr)
Expand Down Expand Up @@ -157,9 +158,10 @@ func (sw *Switch) OnStart() error {

// OnStop implements BaseService. It stops all listeners, peers, and reactors.
func (sw *Switch) OnStop() {
if sw.lanDiscv != nil {
if sw.Config.P2P.LANDiscover {
sw.lanDiscv.Stop()
}

for _, listener := range sw.listeners {
listener.Stop()
}
Expand Down Expand Up @@ -395,7 +397,7 @@ func (sw *Switch) connectLANPeers(lanPeer mdns.LANPeerEvent) {
}

func (sw *Switch) connectLANPeersRoutine() {
if sw.lanDiscv == nil {
if !sw.Config.P2P.LANDiscover {
return
}

Expand Down
1 change: 1 addition & 0 deletions p2p/test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func (m *mockDiscv) ReadRandomNodes(buf []*dht.Node) (n int) {
func MakeSwitch(cfg *cfg.Config, testdb dbm.DB, privKey crypto.PrivKeyEd25519, initSwitch func(*Switch) *Switch) *Switch {
// new switch, add reactors
l, listenAddr := GetListener(cfg.P2P)
cfg.P2P.LANDiscover = false
sw, err := newSwitch(cfg, new(mockDiscv), nil, testdb, l, privKey, listenAddr)
if err != nil {
log.Errorf("create switch error: %s", err)
Expand Down
14 changes: 10 additions & 4 deletions protocol/vm/vmutil/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,20 @@ func checkMultiSigParams(nrequired, npubkeys int64) error {
}

// GetIssuanceProgramRestrictHeight return issuance program restrict height
func GetIssuanceProgramRestrictHeight(program []byte) (int64, error) {
// if height invalid return 0
func GetIssuanceProgramRestrictHeight(program []byte) int64 {
insts, err := vm.ParseProgram(program)
if err != nil {
return 0, err
return 0
}

if len(insts) >= 4 && insts[0].IsPushdata() && insts[1].Op == vm.OP_BLOCKHEIGHT && insts[2].Op == vm.OP_GREATERTHAN && insts[3].Op == vm.OP_VERIFY {
return vm.AsInt64(insts[0].Data)
height, err := vm.AsInt64(insts[0].Data)
if err != nil {
return 0
}

return height
}
return 0, nil
return 0
}
2 changes: 1 addition & 1 deletion protocol/vm/vmutil/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func TestGetIssuanceProgramRestrictHeight(t *testing.T) {
t.Fatal(err)
}

gotHeight, _ := GetIssuanceProgramRestrictHeight(program)
gotHeight := GetIssuanceProgramRestrictHeight(program)
if gotHeight != test.wantHeight {
t.Errorf("TestGetIssuanceProgramRestrictHeight #%d failed: got %d want %d", i, gotHeight, test.wantHeight)
}
Expand Down
1 change: 1 addition & 0 deletions wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ func (w *Wallet) loadWalletInfo() error {
}

w.status.Version = currentVersion
w.status.WorkHash = bc.Hash{}
block, err := w.chain.GetBlockByHeight(0)
if err != nil {
return err
Expand Down

0 comments on commit 8b73700

Please sign in to comment.