Official Go implementation of the Bytom protocol
Revision | db055c74120179350d4a683fccaf511db5e28b7e (tree) |
---|---|
Time | 2019-10-14 11:53:04 |
Author | Paladz <yzhu101@uott...> |
Commiter | GitHub |
Merge pull request #1790 from Bytom/dev
Dev
@@ -107,7 +107,7 @@ available flags for `bytomd node`: | ||
107 | 107 | --vault_mode Run in the offline enviroment |
108 | 108 | --wallet.disable Disable wallet |
109 | 109 | --wallet.rescan Rescan wallet |
110 | - --web.closed Lanch web browser or not | |
110 | + --web.closed Launch web browser or not | |
111 | 111 | --simd.enable Enable the _simd_ feature to speed up the _PoW_ verification (e.g., during mining and block verification) |
112 | 112 | ``` |
113 | 113 |
@@ -38,6 +38,7 @@ type AnnotatedInput struct { | ||
38 | 38 | Arbitrary chainjson.HexBytes `json:"arbitrary,omitempty"` |
39 | 39 | InputID bc.Hash `json:"input_id"` |
40 | 40 | WitnessArguments []chainjson.HexBytes `json:"witness_arguments"` |
41 | + SignData bc.Hash `json:"sign_data,omitempty"` | |
41 | 42 | } |
42 | 43 | |
43 | 44 | //AnnotatedOutput means an annotated transaction output. |
@@ -135,6 +135,9 @@ var MainNetParams = Params{ | ||
135 | 135 | {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})}, |
136 | 136 | {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})}, |
137 | 137 | {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})}, | |
138 | 141 | }, |
139 | 142 | } |
140 | 143 |
@@ -152,6 +155,8 @@ var TestNetParams = Params{ | ||
152 | 155 | {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})}, |
153 | 156 | {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})}, |
154 | 157 | {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})}, | |
155 | 160 | }, |
156 | 161 | } |
157 | 162 |
@@ -87,7 +87,12 @@ func MakeSecretConnection(conn io.ReadWriteCloser, locPrivKey crypto.PrivKeyEd25 | ||
87 | 87 | if err != nil { |
88 | 88 | return nil, err |
89 | 89 | } |
90 | + | |
90 | 91 | 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 | + | |
91 | 96 | if !remPubKey.VerifyBytes(challenge[:], remSignature) { |
92 | 97 | return nil, errors.New("Challenge verification failed") |
93 | 98 | } |
@@ -2,65 +2,68 @@ package mdns | ||
2 | 2 | |
3 | 3 | import ( |
4 | 4 | "context" |
5 | + "fmt" | |
5 | 6 | |
6 | 7 | "github.com/grandcat/zeroconf" |
7 | 8 | ) |
8 | 9 | |
9 | 10 | const ( |
10 | 11 | instanceName = "bytomd" |
11 | - serviceName = "lanDiscover" | |
12 | + serviceName = "bytom%sLanDiscover" | |
12 | 13 | domainName = "local" |
13 | 14 | ) |
14 | 15 | |
15 | 16 | // Protocol decoration ZeroConf,which is a pure Golang library |
16 | 17 | // that employs Multicast DNS-SD. |
17 | 18 | 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{} | |
21 | 23 | } |
22 | 24 | |
23 | 25 | // NewProtocol create a specific Protocol. |
24 | -func NewProtocol() *Protocol { | |
26 | +func NewProtocol(chainID string) *Protocol { | |
25 | 27 | 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{}), | |
28 | 31 | } |
29 | 32 | } |
30 | 33 | |
31 | -func (m *Protocol) getLanPeerLoop(event chan LANPeerEvent) { | |
34 | +func (p *Protocol) getLanPeerLoop(event chan LANPeerEvent) { | |
32 | 35 | for { |
33 | 36 | select { |
34 | - case entry := <-m.entries: | |
37 | + case entry := <-p.entries: | |
35 | 38 | event <- LANPeerEvent{IP: entry.AddrIPv4, Port: entry.Port} |
36 | - case <-m.quite: | |
39 | + case <-p.quite: | |
37 | 40 | return |
38 | 41 | } |
39 | 42 | } |
40 | 43 | } |
41 | 44 | |
42 | -func (m *Protocol) registerService(port int) error { | |
45 | +func (p *Protocol) registerService(port int) error { | |
43 | 46 | 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) | |
45 | 48 | return err |
46 | 49 | } |
47 | 50 | |
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) | |
50 | 53 | resolver, err := zeroconf.NewResolver(nil) |
51 | 54 | if err != nil { |
52 | 55 | return err |
53 | 56 | } |
54 | 57 | |
55 | - return resolver.Browse(context.Background(), serviceName, domainName, m.entries) | |
58 | + return resolver.Browse(context.Background(), p.serviceName, domainName, p.entries) | |
56 | 59 | } |
57 | 60 | |
58 | -func (m *Protocol) stopResolver() { | |
59 | - close(m.quite) | |
61 | +func (p *Protocol) stopResolver() { | |
62 | + close(p.quite) | |
60 | 63 | } |
61 | 64 | |
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() | |
65 | 68 | } |
66 | 69 | } |
@@ -105,7 +105,7 @@ func NewSwitch(config *cfg.Config) (*Switch, error) { | ||
105 | 105 | return nil, err |
106 | 106 | } |
107 | 107 | 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)) | |
109 | 109 | } |
110 | 110 | } |
111 | 111 |
@@ -14,10 +14,10 @@ import ( | ||
14 | 14 | "github.com/bytom/consensus" |
15 | 15 | "github.com/bytom/consensus/segwit" |
16 | 16 | "github.com/bytom/crypto/sha3pool" |
17 | + dbm "github.com/bytom/database/leveldb" | |
17 | 18 | "github.com/bytom/protocol/bc" |
18 | 19 | "github.com/bytom/protocol/bc/types" |
19 | 20 | "github.com/bytom/protocol/vm/vmutil" |
20 | - dbm "github.com/bytom/database/leveldb" | |
21 | 21 | ) |
22 | 22 | |
23 | 23 | // annotateTxs adds asset data to transactions |
@@ -177,6 +177,7 @@ func (w *Wallet) BuildAnnotatedInput(tx *types.Tx, i uint32) *query.AnnotatedInp | ||
177 | 177 | if orig.InputType() != types.CoinbaseInputType { |
178 | 178 | in.AssetID = orig.AssetID() |
179 | 179 | in.Amount = orig.Amount() |
180 | + in.SignData = tx.SigHash(i) | |
180 | 181 | } |
181 | 182 | |
182 | 183 | id := tx.Tx.InputIDs[i] |