• R/O
  • HTTP
  • SSH
  • HTTPS

bytom: Commit

Official Go implementation of the Bytom protocol


Commit MetaInfo

Revisiondb055c74120179350d4a683fccaf511db5e28b7e (tree)
Time2019-10-14 11:53:04
AuthorPaladz <yzhu101@uott...>
CommiterGitHub

Log Message

Merge pull request #1790 from Bytom/dev

Dev

Change Summary

Incremental Difference

--- a/README.md
+++ b/README.md
@@ -107,7 +107,7 @@ available flags for `bytomd node`:
107107 --vault_mode Run in the offline enviroment
108108 --wallet.disable Disable wallet
109109 --wallet.rescan Rescan wallet
110- --web.closed Lanch web browser or not
110+ --web.closed Launch web browser or not
111111 --simd.enable Enable the _simd_ feature to speed up the _PoW_ verification (e.g., during mining and block verification)
112112 ```
113113
--- a/blockchain/query/annotated.go
+++ b/blockchain/query/annotated.go
@@ -38,6 +38,7 @@ type AnnotatedInput struct {
3838 Arbitrary chainjson.HexBytes `json:"arbitrary,omitempty"`
3939 InputID bc.Hash `json:"input_id"`
4040 WitnessArguments []chainjson.HexBytes `json:"witness_arguments"`
41+ SignData bc.Hash `json:"sign_data,omitempty"`
4142 }
4243
4344 //AnnotatedOutput means an annotated transaction output.
--- a/consensus/general.go
+++ b/consensus/general.go
@@ -135,6 +135,9 @@ var MainNetParams = Params{
135135 {191000, bc.NewHash([32]byte{0x09, 0x4f, 0xe3, 0x23, 0x91, 0xb5, 0x11, 0x18, 0x68, 0xcc, 0x99, 0x9f, 0xeb, 0x95, 0xf9, 0xcc, 0xa5, 0x27, 0x6a, 0xf9, 0x0e, 0xda, 0x1b, 0xc6, 0x2e, 0x03, 0x29, 0xfe, 0x08, 0xdd, 0x2b, 0x01})},
136136 {205000, bc.NewHash([32]byte{0x6f, 0xdd, 0x87, 0x26, 0x73, 0x3f, 0x0b, 0xc7, 0x58, 0x64, 0xa4, 0xdf, 0x45, 0xe4, 0x50, 0x27, 0x68, 0x38, 0x18, 0xb9, 0xa9, 0x44, 0x56, 0x20, 0x34, 0x68, 0xd8, 0x68, 0x72, 0xdb, 0x65, 0x6f})},
137137 {219700, bc.NewHash([32]byte{0x98, 0x49, 0x8d, 0x4b, 0x7e, 0xe9, 0x44, 0x55, 0xc1, 0x07, 0xdd, 0x9a, 0xba, 0x6b, 0x49, 0x92, 0x61, 0x15, 0x03, 0x4f, 0x59, 0x42, 0x35, 0x74, 0xea, 0x3b, 0xdb, 0x2c, 0x53, 0x11, 0x75, 0x74})},
138+ {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})},
139+ {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})},
140+ {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})},
138141 },
139142 }
140143
@@ -152,6 +155,8 @@ var TestNetParams = Params{
152155 {83200, bc.NewHash([32]byte{0xb4, 0x6f, 0xc5, 0xcf, 0xa3, 0x3d, 0xe1, 0x11, 0x71, 0x68, 0x40, 0x68, 0x0c, 0xe7, 0x4c, 0xaf, 0x5a, 0x11, 0xfe, 0x82, 0xbc, 0x36, 0x88, 0x0f, 0xbd, 0x04, 0xf0, 0xc4, 0x86, 0xd4, 0xd6, 0xd5})},
153156 {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})},
154157 {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})},
158+ {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})},
159+ {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})},
155160 },
156161 }
157162
--- a/p2p/connection/secret_connection.go
+++ b/p2p/connection/secret_connection.go
@@ -87,7 +87,12 @@ func MakeSecretConnection(conn io.ReadWriteCloser, locPrivKey crypto.PrivKeyEd25
8787 if err != nil {
8888 return nil, err
8989 }
90+
9091 remPubKey, remSignature := authSigMsg.Key, authSigMsg.Sig
92+ if _, ok := remPubKey.PubKeyInner.(crypto.PubKeyEd25519); !ok {
93+ return nil, errors.New("peer sent a nil public key")
94+ }
95+
9196 if !remPubKey.VerifyBytes(challenge[:], remSignature) {
9297 return nil, errors.New("Challenge verification failed")
9398 }
--- a/p2p/discover/mdns/mdns.go
+++ b/p2p/discover/mdns/mdns.go
@@ -2,65 +2,68 @@ package mdns
22
33 import (
44 "context"
5+ "fmt"
56
67 "github.com/grandcat/zeroconf"
78 )
89
910 const (
1011 instanceName = "bytomd"
11- serviceName = "lanDiscover"
12+ serviceName = "bytom%sLanDiscover"
1213 domainName = "local"
1314 )
1415
1516 // Protocol decoration ZeroConf,which is a pure Golang library
1617 // that employs Multicast DNS-SD.
1718 type Protocol struct {
18- entries chan *zeroconf.ServiceEntry
19- server *zeroconf.Server
20- quite chan struct{}
19+ entries chan *zeroconf.ServiceEntry
20+ server *zeroconf.Server
21+ serviceName string
22+ quite chan struct{}
2123 }
2224
2325 // NewProtocol create a specific Protocol.
24-func NewProtocol() *Protocol {
26+func NewProtocol(chainID string) *Protocol {
2527 return &Protocol{
26- entries: make(chan *zeroconf.ServiceEntry),
27- quite: make(chan struct{}),
28+ entries: make(chan *zeroconf.ServiceEntry),
29+ serviceName: fmt.Sprintf(serviceName, chainID),
30+ quite: make(chan struct{}),
2831 }
2932 }
3033
31-func (m *Protocol) getLanPeerLoop(event chan LANPeerEvent) {
34+func (p *Protocol) getLanPeerLoop(event chan LANPeerEvent) {
3235 for {
3336 select {
34- case entry := <-m.entries:
37+ case entry := <-p.entries:
3538 event <- LANPeerEvent{IP: entry.AddrIPv4, Port: entry.Port}
36- case <-m.quite:
39+ case <-p.quite:
3740 return
3841 }
3942 }
4043 }
4144
42-func (m *Protocol) registerService(port int) error {
45+func (p *Protocol) registerService(port int) error {
4346 var err error
44- m.server, err = zeroconf.Register(instanceName, serviceName, domainName, port, nil, nil)
47+ p.server, err = zeroconf.Register(instanceName, p.serviceName, domainName, port, nil, nil)
4548 return err
4649 }
4750
48-func (m *Protocol) registerResolver(event chan LANPeerEvent) error {
49- go m.getLanPeerLoop(event)
51+func (p *Protocol) registerResolver(event chan LANPeerEvent) error {
52+ go p.getLanPeerLoop(event)
5053 resolver, err := zeroconf.NewResolver(nil)
5154 if err != nil {
5255 return err
5356 }
5457
55- return resolver.Browse(context.Background(), serviceName, domainName, m.entries)
58+ return resolver.Browse(context.Background(), p.serviceName, domainName, p.entries)
5659 }
5760
58-func (m *Protocol) stopResolver() {
59- close(m.quite)
61+func (p *Protocol) stopResolver() {
62+ close(p.quite)
6063 }
6164
62-func (m *Protocol) stopService() {
63- if m.server != nil {
64- m.server.Shutdown()
65+func (p *Protocol) stopService() {
66+ if p.server != nil {
67+ p.server.Shutdown()
6568 }
6669 }
--- a/p2p/switch.go
+++ b/p2p/switch.go
@@ -105,7 +105,7 @@ func NewSwitch(config *cfg.Config) (*Switch, error) {
105105 return nil, err
106106 }
107107 if config.P2P.LANDiscover {
108- lanDiscv = mdns.NewLANDiscover(mdns.NewProtocol(), int(l.ExternalAddress().Port))
108+ lanDiscv = mdns.NewLANDiscover(mdns.NewProtocol(config.ChainID), int(l.ExternalAddress().Port))
109109 }
110110 }
111111
--- a/wallet/annotated.go
+++ b/wallet/annotated.go
@@ -14,10 +14,10 @@ import (
1414 "github.com/bytom/consensus"
1515 "github.com/bytom/consensus/segwit"
1616 "github.com/bytom/crypto/sha3pool"
17+ dbm "github.com/bytom/database/leveldb"
1718 "github.com/bytom/protocol/bc"
1819 "github.com/bytom/protocol/bc/types"
1920 "github.com/bytom/protocol/vm/vmutil"
20- dbm "github.com/bytom/database/leveldb"
2121 )
2222
2323 // annotateTxs adds asset data to transactions
@@ -177,6 +177,7 @@ func (w *Wallet) BuildAnnotatedInput(tx *types.Tx, i uint32) *query.AnnotatedInp
177177 if orig.InputType() != types.CoinbaseInputType {
178178 in.AssetID = orig.AssetID()
179179 in.Amount = orig.Amount()
180+ in.SignData = tx.SigHash(i)
180181 }
181182
182183 id := tx.Tx.InputIDs[i]
Show on old repository browser