[DEV-353] Rename subnetwork to subnetworkID everywhere in the code except for the command line flag (#165)

* [DEV-353] Renamed subnetwork -> subnetworkID.

* [DEV-353] Renamed dagcoin -> native.
This commit is contained in:
stasatdaglabs 2019-01-20 16:22:25 +02:00 committed by Evgeny Khirin
parent 10ee7df252
commit f00651c4e3
28 changed files with 115 additions and 143 deletions

View File

@ -96,10 +96,6 @@ type BlockDAG struct {
// virtual tracks the current tips.
virtual *virtualBlock
// lastSubnetworkID holds the last registered subnetwork ID in the DAG.
// Note that it is NOT the total amount of registered (or active) subnetworks.
lastSubnetworkID uint64
// These fields are related to handling of orphan blocks. They are
// protected by a combination of the chain lock and the orphan lock.
orphanLock sync.RWMutex

View File

@ -53,14 +53,6 @@ var (
// unspent transaction output set.
utxoSetBucketName = []byte("utxoset")
// pendingSubnetworksBucketName is the name of the db bucket used to store the
// pending subnetworks.
pendingSubnetworksBucketName = []byte("pendingsubnetworks")
// registeredSubnetworkTxsBucketName is the name of the db bucket used to house
// the transactions that have been used to register subnetworks.
registeredSubnetworkTxsBucketName = []byte("registeredsubnetworktxs")
// subnetworksBucketName is the name of the db bucket used to store the
// subnetwork registry.
subnetworksBucketName = []byte("subnetworks")
@ -670,7 +662,6 @@ func dbFetchHeightByHash(dbTx database.Tx, hash *daghash.Hash) (int32, error) {
type dagState struct {
TipHashes []daghash.Hash
LastFinalityPoint daghash.Hash
LastSubnetworkID uint64
}
// serializeDAGState returns the serialization of the DAG state.
@ -776,19 +767,6 @@ func (dag *BlockDAG) createDAGState() error {
return err
}
// Create the bucket that houses the pending subnetworks.
_, err = meta.CreateBucket(pendingSubnetworksBucketName)
if err != nil {
return err
}
// Create the bucket that houses the registered subnetworks to
// their registry transactions index.
_, err = meta.CreateBucket(registeredSubnetworkTxsBucketName)
if err != nil {
return err
}
// Create the bucket that houses the registered subnetworks.
_, err = meta.CreateBucket(subnetworksBucketName)
if err != nil {

View File

@ -547,18 +547,16 @@ func TestDAGStateSerialization(t *testing.T) {
state: &dagState{
TipHashes: []daghash.Hash{*newHashFromStr("000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f")},
LastFinalityPoint: *newHashFromStr("000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"),
LastSubnetworkID: 123456,
},
serialized: []byte("{\"TipHashes\":[[111,226,140,10,182,241,179,114,193,166,162,70,174,99,247,79,147,30,131,101,225,90,8,156,104,214,25,0,0,0,0,0]],\"LastFinalityPoint\":[111,226,140,10,182,241,179,114,193,166,162,70,174,99,247,79,147,30,131,101,225,90,8,156,104,214,25,0,0,0,0,0],\"LastSubnetworkID\":123456}"),
serialized: []byte("{\"TipHashes\":[[111,226,140,10,182,241,179,114,193,166,162,70,174,99,247,79,147,30,131,101,225,90,8,156,104,214,25,0,0,0,0,0]],\"LastFinalityPoint\":[111,226,140,10,182,241,179,114,193,166,162,70,174,99,247,79,147,30,131,101,225,90,8,156,104,214,25,0,0,0,0,0]}"),
},
{
name: "block 1",
state: &dagState{
TipHashes: []daghash.Hash{*newHashFromStr("00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048")},
LastFinalityPoint: *newHashFromStr("000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"),
LastSubnetworkID: 684321,
},
serialized: []byte("{\"TipHashes\":[[72,96,235,24,191,27,22,32,227,126,148,144,252,138,66,117,20,65,111,215,81,89,171,134,104,142,154,131,0,0,0,0]],\"LastFinalityPoint\":[111,226,140,10,182,241,179,114,193,166,162,70,174,99,247,79,147,30,131,101,225,90,8,156,104,214,25,0,0,0,0,0],\"LastSubnetworkID\":684321}"),
serialized: []byte("{\"TipHashes\":[[72,96,235,24,191,27,22,32,227,126,148,144,252,138,66,117,20,65,111,215,81,89,171,134,104,142,154,131,0,0,0,0]],\"LastFinalityPoint\":[111,226,140,10,182,241,179,114,193,166,162,70,174,99,247,79,147,30,131,101,225,90,8,156,104,214,25,0,0,0,0,0]}"),
},
}

View File

@ -84,7 +84,7 @@ var (
"4c702b6bf11d5fac"),
}},
LockTime: 0,
SubnetworkID: wire.SubnetworkDAGCoin,
SubnetworkID: wire.SubnetworkIDNative,
}},
}
)

View File

@ -151,7 +151,7 @@ var block1 = wire.MsgBlock{
},
},
LockTime: 0,
SubnetworkID: wire.SubnetworkDAGCoin,
SubnetworkID: wire.SubnetworkIDNative,
},
},
}
@ -205,7 +205,7 @@ var block2 = wire.MsgBlock{
},
},
LockTime: 0,
SubnetworkID: wire.SubnetworkDAGCoin,
SubnetworkID: wire.SubnetworkIDNative,
},
{
Version: 1,
@ -251,7 +251,7 @@ var block2 = wire.MsgBlock{
},
},
LockTime: 0,
SubnetworkID: wire.SubnetworkDAGCoin,
SubnetworkID: wire.SubnetworkIDNative,
},
},
}
@ -300,7 +300,7 @@ var block3Tx = &wire.MsgTx{
},
},
LockTime: 0,
SubnetworkID: wire.SubnetworkDAGCoin,
SubnetworkID: wire.SubnetworkIDNative,
}
var block3 = wire.MsgBlock{
@ -352,7 +352,7 @@ var block3 = wire.MsgBlock{
},
},
LockTime: 0,
SubnetworkID: wire.SubnetworkDAGCoin,
SubnetworkID: wire.SubnetworkIDNative,
},
block3Tx,
},
@ -407,7 +407,7 @@ var block3A = wire.MsgBlock{
},
},
LockTime: 0,
SubnetworkID: wire.SubnetworkDAGCoin,
SubnetworkID: wire.SubnetworkIDNative,
},
block3Tx,
},
@ -462,7 +462,7 @@ var block4 = wire.MsgBlock{
},
},
LockTime: 0,
SubnetworkID: wire.SubnetworkDAGCoin,
SubnetworkID: wire.SubnetworkIDNative,
},
},
}
@ -522,7 +522,7 @@ var block5 = wire.MsgBlock{
},
},
LockTime: 0,
SubnetworkID: wire.SubnetworkDAGCoin,
SubnetworkID: wire.SubnetworkIDNative,
},
},
}

View File

@ -19,7 +19,7 @@ func registerSubnetworks(dbTx database.Tx, txs []*TxWithBlockHash) error {
validSubnetworkRegistryTxs := make([]*wire.MsgTx, 0)
for _, txData := range txs {
tx := txData.Tx.MsgTx()
if tx.SubnetworkID == wire.SubnetworkRegistry {
if tx.SubnetworkID == wire.SubnetworkIDRegistry {
err := validateSubnetworkRegistryTransaction(tx)
if err != nil {
return err
@ -27,7 +27,7 @@ func registerSubnetworks(dbTx database.Tx, txs []*TxWithBlockHash) error {
validSubnetworkRegistryTxs = append(validSubnetworkRegistryTxs, tx)
}
if subnetworkid.Less(&wire.SubnetworkRegistry, &tx.SubnetworkID) {
if subnetworkid.Less(&wire.SubnetworkIDRegistry, &tx.SubnetworkID) {
// Transactions are ordered by subnetwork, so we can safely assume
// that the rest of the transactions will not be subnetwork registry
// transactions.

View File

@ -133,7 +133,7 @@ func createTxForTest(numInputs uint32, numOutputs uint32, outputValue uint64, su
tx.Gas = subnetworkData.Gas
tx.Payload = subnetworkData.Payload
} else {
tx.SubnetworkID = wire.SubnetworkDAGCoin
tx.SubnetworkID = wire.SubnetworkIDNative
tx.Gas = 0
tx.Payload = []byte{}
}
@ -229,7 +229,7 @@ func RegisterSubnetworkForTest(dag *BlockDAG, gasLimit uint64) (*subnetworkid.Su
// Create a block with a valid subnetwork registry transaction
registryTx := wire.NewMsgTx(wire.TxVersion)
registryTx.SubnetworkID = wire.SubnetworkRegistry
registryTx.SubnetworkID = wire.SubnetworkIDRegistry
registryTx.Payload = make([]byte, 8)
binary.LittleEndian.PutUint64(registryTx.Payload, gasLimit)

View File

@ -262,23 +262,23 @@ func CheckTransactionSanity(tx *util.Tx) error {
}
}
// Transactions in native and SubnetworkRegistry Subnetworks must have Gas = 0
if (msgTx.SubnetworkID == wire.SubnetworkDAGCoin ||
msgTx.SubnetworkID == wire.SubnetworkRegistry) &&
// Transactions in native and subnetwork registry subnetworks must have Gas = 0
if (msgTx.SubnetworkID == wire.SubnetworkIDNative ||
msgTx.SubnetworkID == wire.SubnetworkIDRegistry) &&
msgTx.Gas > 0 {
return ruleError(ErrInvalidGas, "transaction in the native or "+
"registry subnetworks has gas > 0 ")
}
if msgTx.SubnetworkID == wire.SubnetworkDAGCoin &&
if msgTx.SubnetworkID == wire.SubnetworkIDNative &&
len(msgTx.Payload) > 0 {
return ruleError(ErrInvalidPayload,
"transaction in the native subnetwork includes a payload")
}
if msgTx.SubnetworkID == wire.SubnetworkRegistry &&
if msgTx.SubnetworkID == wire.SubnetworkIDRegistry &&
len(msgTx.Payload) != 8 {
return ruleError(ErrInvalidPayload,

View File

@ -753,7 +753,7 @@ var Block100000 = wire.MsgBlock{
},
},
LockTime: 0,
SubnetworkID: wire.SubnetworkDAGCoin,
SubnetworkID: wire.SubnetworkIDNative,
},
{
Version: 1,
@ -822,7 +822,7 @@ var Block100000 = wire.MsgBlock{
},
},
LockTime: 0,
SubnetworkID: wire.SubnetworkDAGCoin,
SubnetworkID: wire.SubnetworkIDNative,
},
{
Version: 1,
@ -879,7 +879,7 @@ var Block100000 = wire.MsgBlock{
},
},
LockTime: 0,
SubnetworkID: wire.SubnetworkDAGCoin,
SubnetworkID: wire.SubnetworkIDNative,
},
},
}
@ -1084,7 +1084,7 @@ var BlockWithWrongTxOrder = wire.MsgBlock{
},
},
LockTime: 0,
SubnetworkID: wire.SubnetworkDAGCoin,
SubnetworkID: wire.SubnetworkIDNative,
},
{
Version: 1,
@ -1141,7 +1141,7 @@ var BlockWithWrongTxOrder = wire.MsgBlock{
},
},
LockTime: 0,
SubnetworkID: wire.SubnetworkDAGCoin,
SubnetworkID: wire.SubnetworkIDNative,
},
},
}
@ -1165,17 +1165,17 @@ func TestCheckTransactionSanity(t *testing.T) {
{"duplicate inputs", 2, 1, 1, nil,
func(tx *wire.MsgTx) { tx.TxIn[1].PreviousOutPoint.Index = 0 },
ruleError(ErrDuplicateTxInputs, "")},
{"non-zero gas in DAGCoin", 1, 1, 0,
&txSubnetworkData{wire.SubnetworkDAGCoin, 1, []byte{}},
{"non-zero gas in native subnetwork", 1, 1, 0,
&txSubnetworkData{wire.SubnetworkIDNative, 1, []byte{}},
nil, ruleError(ErrInvalidGas, "")},
{"non-zero gas in subnetwork registry", 1, 1, 0,
&txSubnetworkData{wire.SubnetworkRegistry, 1, []byte{}},
&txSubnetworkData{wire.SubnetworkIDRegistry, 1, []byte{}},
nil, ruleError(ErrInvalidGas, "")},
{"non-zero payload in DAGCoin", 1, 1, 0,
&txSubnetworkData{wire.SubnetworkDAGCoin, 0, []byte{1}},
{"non-zero payload in native subnetwork", 1, 1, 0,
&txSubnetworkData{wire.SubnetworkIDNative, 0, []byte{1}},
nil, ruleError(ErrInvalidPayload, "")},
{"payload in subnetwork registry isn't 8 bytes", 1, 1, 0,
&txSubnetworkData{wire.SubnetworkRegistry, 0, []byte{1, 2, 3, 4, 5, 6, 7}},
&txSubnetworkData{wire.SubnetworkIDRegistry, 0, []byte{1, 2, 3, 4, 5, 6, 7}},
nil, ruleError(ErrInvalidPayload, "")},
}

View File

@ -181,7 +181,7 @@ type Config struct {
MiningAddrs []util.Address
MinRelayTxFee util.Amount
Whitelists []*net.IPNet
Subnetwork *subnetworkid.SubnetworkID
SubnetworkID *subnetworkid.SubnetworkID
}
// serviceOptions defines the configuration options for the daemon as a service on
@ -754,14 +754,14 @@ func loadConfig() (*Config, []string, error) {
}
if cfg.configFlags.Subnetwork != "" {
cfg.Subnetwork, err = subnetworkid.NewFromStr(cfg.configFlags.Subnetwork)
cfg.SubnetworkID, err = subnetworkid.NewFromStr(cfg.configFlags.Subnetwork)
if err != nil {
return nil, nil, err
}
}
// Check that 'generate' and 'subnetwork' flags do not conflict
if cfg.Generate && *cfg.Subnetwork != wire.SubnetworkSupportsAll {
if cfg.Generate && *cfg.SubnetworkID != wire.SubnetworkIDSupportsAll {
str := "%s: both generate flag and subnetwork filtering are set "
err := fmt.Errorf(str, funcName)
fmt.Fprintln(os.Stderr, err)

View File

@ -77,7 +77,7 @@ func TestCreateDefaultConfigFile(t *testing.T) {
// TestConstants makes sure that all constants hard-coded into the help text were not modified.
func TestConstants(t *testing.T) {
zero := subnetworkid.SubnetworkID{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
if wire.SubnetworkSupportsAll != zero {
t.Errorf("wire.SubnetworkSupportsAll value was changed from 0, therefore you probably need to update the help text for Subnetwork")
if wire.SubnetworkIDSupportsAll != zero {
t.Errorf("wire.SubnetworkIDSupportsAll value was changed from 0, therefore you probably need to update the help text for SubnetworkID")
}
}

View File

@ -54,7 +54,7 @@ var genesisCoinbaseTx = wire.MsgTx{
},
},
LockTime: 0,
SubnetworkID: wire.SubnetworkDAGCoin,
SubnetworkID: wire.SubnetworkIDNative,
}
// genesisHash is the hash of the first block in the block chain for the main

View File

@ -143,7 +143,7 @@ var genesisCoinbaseTx = wire.MsgTx{
},
},
LockTime: 0,
SubnetworkID: wire.SubnetworkDAGCoin,
SubnetworkID: wire.SubnetworkIDNative,
}
var genesisMerkleRoot = daghash.Hash([daghash.HashSize]byte{ // Make go vet happy.

View File

@ -659,9 +659,9 @@ func (mp *TxPool) maybeAcceptTransaction(tx *util.Tx, isNew, rateLimit, rejectDu
// Check that transaction does not overuse GAS
msgTx := tx.MsgTx()
if msgTx.SubnetworkID == wire.SubnetworkSupportsAll {
return nil, nil, txRuleError(wire.RejectInvalid, "Subnetwork 0 is not permited in transaction")
} else if msgTx.SubnetworkID != wire.SubnetworkDAGCoin {
if msgTx.SubnetworkID == wire.SubnetworkIDSupportsAll {
return nil, nil, txRuleError(wire.RejectInvalid, "SubnetworkIDSupportsAll is not permited in transaction")
} else if msgTx.SubnetworkID != wire.SubnetworkIDNative {
gasLimit, err := mp.cfg.DAG.GasLimit(&msgTx.SubnetworkID)
if err != nil {
return nil, nil, err

View File

@ -211,7 +211,7 @@ func (p *poolHarness) CreateSignedTxForSubnetwork(inputs []spendableOutpoint, nu
// total input amount. All outputs will be to the payment script associated
// with the harness and all inputs are assumed to do the same.
func (p *poolHarness) CreateSignedTx(inputs []spendableOutpoint, numOutputs uint32) (*util.Tx, error) {
return p.CreateSignedTxForSubnetwork(inputs, numOutputs, &wire.SubnetworkDAGCoin, 0)
return p.CreateSignedTxForSubnetwork(inputs, numOutputs, &wire.SubnetworkIDNative, 0)
}
// CreateTxChain creates a chain of zero-fee transactions (each subsequent
@ -610,7 +610,7 @@ func TestProcessTransaction(t *testing.T) {
PkScript: p2shPKScript,
}},
LockTime: 0,
SubnetworkID: wire.SubnetworkDAGCoin,
SubnetworkID: wire.SubnetworkIDNative,
})
harness.txPool.mpUTXOSet.AddTx(p2shTx.MsgTx(), curHeight+1)
@ -626,7 +626,7 @@ func TestProcessTransaction(t *testing.T) {
PkScript: dummyPkScript,
}},
LockTime: 0,
SubnetworkID: wire.SubnetworkDAGCoin,
SubnetworkID: wire.SubnetworkIDNative,
})
_, err = harness.txPool.ProcessTransaction(nonStdSigScriptTx, true, false, 0)
if err == nil {
@ -671,7 +671,7 @@ func TestProcessTransaction(t *testing.T) {
}},
TxOut: []*wire.TxOut{},
LockTime: 0,
SubnetworkID: wire.SubnetworkDAGCoin,
SubnetworkID: wire.SubnetworkIDNative,
})
_, err = harness.txPool.ProcessTransaction(noOutsTx, true, false, 0)
if err == nil {
@ -748,7 +748,7 @@ func TestProcessTransaction(t *testing.T) {
PkScript: dummyPkScript,
}},
LockTime: 0,
SubnetworkID: wire.SubnetworkDAGCoin,
SubnetworkID: wire.SubnetworkIDNative,
})
_, err = harness.txPool.ProcessTransaction(tx, true, false, 0)
fmt.Println(err)
@ -1830,7 +1830,7 @@ var dummyBlock = wire.MsgBlock{
},
},
LockTime: 0,
SubnetworkID: wire.SubnetworkDAGCoin,
SubnetworkID: wire.SubnetworkIDNative,
},
},
}

View File

@ -485,24 +485,24 @@ func (g *BlkTmplGenerator) NewBlockTemplate(payToAddress util.Address) (*BlockTe
prioItem := heap.Pop(priorityQueue).(*txPrioItem)
tx := prioItem.tx
if tx.MsgTx().SubnetworkID != wire.SubnetworkDAGCoin {
subnetwork := tx.MsgTx().SubnetworkID
gasUsage, ok := gasUsageMap[subnetwork]
if tx.MsgTx().SubnetworkID != wire.SubnetworkIDNative {
subnetworkID := tx.MsgTx().SubnetworkID
gasUsage, ok := gasUsageMap[subnetworkID]
if !ok {
gasUsage = 0
}
gasLimit, err := g.dag.GasLimit(&subnetwork)
gasLimit, err := g.dag.GasLimit(&subnetworkID)
if err != nil {
log.Errorf("Cannot get GAS limit for subnetwork %v", subnetwork)
log.Errorf("Cannot get GAS limit for subnetwork %v", subnetworkID)
continue
}
txGas := tx.MsgTx().Gas
if gasLimit-gasUsage < txGas {
log.Tracef("Transaction %v (GAS=%v) ignored because gas overusage (GASUsage=%v) in subnetwork %v (GASLimit=%v)",
tx.MsgTx().TxHash, txGas, gasUsage, subnetwork, gasLimit)
tx.MsgTx().TxHash, txGas, gasUsage, subnetworkID, gasLimit)
continue
}
gasUsageMap[subnetwork] = gasUsage + txGas
gasUsageMap[subnetworkID] = gasUsage + txGas
}
// Enforce maximum block size. Also check for overflow.

View File

@ -23,7 +23,7 @@ func mockRemotePeer() error {
UserAgentName: "peer", // User agent name to advertise.
UserAgentVersion: "1.0.0", // User agent version to advertise.
DAGParams: &dagconfig.SimNetParams,
Subnetwork: &wire.SubnetworkSupportsAll,
SubnetworkID: &wire.SubnetworkIDSupportsAll,
}
// Accept connections on the simnet port.
@ -78,7 +78,7 @@ func Example_newOutboundPeer() {
verack <- struct{}{}
},
},
Subnetwork: &wire.SubnetworkSupportsAll,
SubnetworkID: &wire.SubnetworkIDSupportsAll,
}
p, err := peer.NewOutboundPeer(peerCfg, "127.0.0.1:18555")
if err != nil {

View File

@ -271,8 +271,8 @@ type Config struct {
// messages.
Listeners MessageListeners
// Subnetwork specifies which subnetwork the peer is associated with.
Subnetwork *subnetworkid.SubnetworkID
// SubnetworkID specifies which subnetwork the peer is associated with.
SubnetworkID *subnetworkid.SubnetworkID
}
// minUint32 is a helper function to return the minimum of two uint32s.
@ -823,7 +823,7 @@ func (p *Peer) localVersionMsg() (*wire.MsgVersion, error) {
nonce := uint64(rand.Int63())
sentNonces.Add(nonce)
subnetworkID := p.cfg.Subnetwork
subnetworkID := p.cfg.SubnetworkID
// Version message.
msg := wire.NewMsgVersion(ourNA, theirNA, nonce, blockNum, subnetworkID)
@ -1045,10 +1045,10 @@ func (p *Peer) handleRemoteVersionMsg(msg *wire.MsgVersion) error {
// Disconnect if:
// - we are a full node and the outbound connection we've initiated is a partial node
// - the remote node is partial and our subnetwork doesn't match their subnetwork
isLocalNodeFull := p.cfg.Subnetwork.IsEqual(&wire.SubnetworkSupportsAll)
isRemoteNodeFull := msg.Subnetwork.IsEqual(&wire.SubnetworkSupportsAll)
isLocalNodeFull := p.cfg.SubnetworkID.IsEqual(&wire.SubnetworkIDSupportsAll)
isRemoteNodeFull := msg.SubnetworkID.IsEqual(&wire.SubnetworkIDSupportsAll)
if (isLocalNodeFull && !isRemoteNodeFull && !p.inbound) ||
(!isRemoteNodeFull && !msg.Subnetwork.IsEqual(p.cfg.Subnetwork)) {
(!isRemoteNodeFull && !msg.SubnetworkID.IsEqual(p.cfg.SubnetworkID)) {
return errors.New("incompatible subnetworks")
}

View File

@ -229,7 +229,7 @@ func TestPeerConnection(t *testing.T) {
DAGParams: &dagconfig.MainNetParams,
ProtocolVersion: wire.RejectVersion, // Configure with older version
Services: 0,
Subnetwork: &wire.SubnetworkSupportsAll,
SubnetworkID: &wire.SubnetworkIDSupportsAll,
}
peer2Cfg := &peer.Config{
Listeners: peer1Cfg.Listeners,
@ -238,7 +238,7 @@ func TestPeerConnection(t *testing.T) {
UserAgentComments: []string{"comment"},
DAGParams: &dagconfig.MainNetParams,
Services: wire.SFNodeNetwork,
Subnetwork: &wire.SubnetworkSupportsAll,
SubnetworkID: &wire.SubnetworkIDSupportsAll,
}
wantStats1 := peerStats{
@ -440,7 +440,7 @@ func TestPeerListeners(t *testing.T) {
UserAgentComments: []string{"comment"},
DAGParams: &dagconfig.MainNetParams,
Services: wire.SFNodeBloom,
Subnetwork: &wire.SubnetworkSupportsAll,
SubnetworkID: &wire.SubnetworkIDSupportsAll,
}
inConn, outConn := pipe(
&conn{raddr: "10.0.0.1:8333"},
@ -611,7 +611,7 @@ func TestOutboundPeer(t *testing.T) {
UserAgentComments: []string{"comment"},
DAGParams: &dagconfig.MainNetParams,
Services: 0,
Subnetwork: &wire.SubnetworkSupportsAll,
SubnetworkID: &wire.SubnetworkIDSupportsAll,
}
r, w := io.Pipe()
@ -752,7 +752,7 @@ func TestUnsupportedVersionPeer(t *testing.T) {
UserAgentComments: []string{"comment"},
DAGParams: &dagconfig.MainNetParams,
Services: 0,
Subnetwork: &wire.SubnetworkSupportsAll,
SubnetworkID: &wire.SubnetworkIDSupportsAll,
}
localNA := wire.NewNetAddressIPPort(
@ -809,7 +809,7 @@ func TestUnsupportedVersionPeer(t *testing.T) {
}
// Remote peer writes version message advertising invalid protocol version 1
invalidVersionMsg := wire.NewMsgVersion(remoteNA, localNA, 0, 0, &wire.SubnetworkSupportsAll)
invalidVersionMsg := wire.NewMsgVersion(remoteNA, localNA, 0, 0, &wire.SubnetworkIDSupportsAll)
invalidVersionMsg.ProtocolVersion = 1
_, err = wire.WriteMessageN(

View File

@ -1816,7 +1816,7 @@ func newPeerConfig(sp *Peer) *peer.Config {
Services: sp.server.services,
DisableRelayTx: config.MainConfig().BlocksOnly,
ProtocolVersion: peer.MaxProtocolVersion,
Subnetwork: config.MainConfig().Subnetwork,
SubnetworkID: config.MainConfig().SubnetworkID,
}
}

View File

@ -889,7 +889,7 @@ func handleGenerate(s *Server, cmd interface{}, closeChan <-chan struct{}) (inte
}
}
if !config.MainConfig().Subnetwork.IsEqual(&wire.SubnetworkSupportsAll) {
if !config.MainConfig().SubnetworkID.IsEqual(&wire.SubnetworkIDSupportsAll) {
return nil, &btcjson.RPCError{
Code: btcjson.ErrRPCInvalidRequest.Code,
Message: "`generate` is not supported on partial nodes.",
@ -2230,7 +2230,7 @@ func handleGetGenerate(s *Server, cmd interface{}, closeChan <-chan struct{}) (i
// handleGetHashesPerSec implements the getHashesPerSec command.
func handleGetHashesPerSec(s *Server, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
if !config.MainConfig().Subnetwork.IsEqual(&wire.SubnetworkSupportsAll) {
if !config.MainConfig().SubnetworkID.IsEqual(&wire.SubnetworkIDSupportsAll) {
return nil, &btcjson.RPCError{
Code: btcjson.ErrRPCInvalidRequest.Code,
Message: "`getHashesPerSec` is not supported on partial nodes.",
@ -2319,7 +2319,7 @@ func handleGetMempoolInfo(s *Server, cmd interface{}, closeChan <-chan struct{})
// handleGetMiningInfo implements the getMiningInfo command. We only return the
// fields that are not related to wallet functionality.
func handleGetMiningInfo(s *Server, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
if !config.MainConfig().Subnetwork.IsEqual(&wire.SubnetworkSupportsAll) {
if !config.MainConfig().SubnetworkID.IsEqual(&wire.SubnetworkIDSupportsAll) {
return nil, &btcjson.RPCError{
Code: btcjson.ErrRPCInvalidRequest.Code,
Message: "`getMiningInfo` is not supported on partial nodes.",
@ -2381,7 +2381,7 @@ func handleGetNetTotals(s *Server, cmd interface{}, closeChan <-chan struct{}) (
// This command had been (possibly temporarily) dropped.
// Originally it relied on height, which no longer makes sense.
func handleGetNetworkHashPS(s *Server, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
if !config.MainConfig().Subnetwork.IsEqual(&wire.SubnetworkSupportsAll) {
if !config.MainConfig().SubnetworkID.IsEqual(&wire.SubnetworkIDSupportsAll) {
return nil, &btcjson.RPCError{
Code: btcjson.ErrRPCInvalidRequest.Code,
Message: "`getNetworkHashPS` is not supported on partial nodes.",
@ -3286,7 +3286,7 @@ func handleSendRawTransaction(s *Server, cmd interface{}, closeChan <-chan struc
// handleSetGenerate implements the setGenerate command.
func handleSetGenerate(s *Server, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
if !config.MainConfig().Subnetwork.IsEqual(&wire.SubnetworkSupportsAll) {
if !config.MainConfig().SubnetworkID.IsEqual(&wire.SubnetworkIDSupportsAll) {
return nil, &btcjson.RPCError{
Code: btcjson.ErrRPCInvalidRequest.Code,
Message: "`setGenerate` is not supported on partial nodes.",

View File

@ -362,7 +362,7 @@ var Block100000 = wire.MsgBlock{
},
},
LockTime: 0,
SubnetworkID: wire.SubnetworkDAGCoin,
SubnetworkID: wire.SubnetworkIDNative,
},
{
Version: 1,
@ -432,7 +432,7 @@ var Block100000 = wire.MsgBlock{
},
},
LockTime: 0,
SubnetworkID: wire.SubnetworkDAGCoin,
SubnetworkID: wire.SubnetworkIDNative,
},
{
Version: 1,
@ -501,7 +501,7 @@ var Block100000 = wire.MsgBlock{
},
},
LockTime: 0,
SubnetworkID: wire.SubnetworkDAGCoin,
SubnetworkID: wire.SubnetworkIDNative,
},
{
Version: 1,
@ -558,7 +558,7 @@ var Block100000 = wire.MsgBlock{
},
},
LockTime: 0,
SubnetworkID: wire.SubnetworkDAGCoin,
SubnetworkID: wire.SubnetworkIDNative,
},
},
}

View File

@ -46,7 +46,7 @@ func TestMessage(t *testing.T) {
addrMe := &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 8333}
me := NewNetAddress(addrMe, SFNodeNetwork)
me.Timestamp = time.Time{} // Version message has zero value timestamp.
msgVersion := NewMsgVersion(me, you, 123123, 0, &SubnetworkSupportsAll)
msgVersion := NewMsgVersion(me, you, 123123, 0, &SubnetworkIDSupportsAll)
msgVerack := NewMsgVerAck()
msgGetAddr := NewMsgGetAddr()

View File

@ -533,7 +533,7 @@ var blockOne = MsgBlock{
},
},
LockTime: 0,
SubnetworkID: SubnetworkDAGCoin,
SubnetworkID: SubnetworkIDNative,
},
},
}
@ -585,7 +585,7 @@ var blockOneBytes = []byte{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Lock time
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, // Subnetwork ID
0x00, 0x00, 0x00, 0x00, // SubnetworkID
}
// Transaction location information for block one transactions.

View File

@ -99,14 +99,14 @@ const (
)
var (
// SubnetworkSupportsAll is the subnetwork id that is used to signal to peers that you support all subnetworks
SubnetworkSupportsAll = subnetworkid.SubnetworkID{}
// SubnetworkIDSupportsAll is the subnetwork ID that is used to signal to peers that you support all subnetworks
SubnetworkIDSupportsAll = subnetworkid.SubnetworkID{}
// SubnetworkDAGCoin is the default subnetwork which is used for transactions without related payload data
SubnetworkDAGCoin = subnetworkid.SubnetworkID{1}
// SubnetworkIDNative is the default subnetwork ID which is used for transactions without related payload data
SubnetworkIDNative = subnetworkid.SubnetworkID{1}
// SubnetworkRegistry is the subnetwork which is used for adding new sub networks to the registry
SubnetworkRegistry = subnetworkid.SubnetworkID{2}
// SubnetworkIDRegistry is the subnetwork ID which is used for adding new sub networks to the registry
SubnetworkIDRegistry = subnetworkid.SubnetworkID{2}
)
// scriptFreeList defines a free list of byte slices (up to the maximum number
@ -464,12 +464,12 @@ func (msg *MsgTx) BtcDecode(r io.Reader, pver uint32) error {
return err
}
if msg.SubnetworkID == SubnetworkSupportsAll {
if msg.SubnetworkID == SubnetworkIDSupportsAll {
str := fmt.Sprintf("%v is a reserved sub network and cannot be used as part of a transaction", msg.SubnetworkID)
return messageError("MsgTx.BtcDecode", str)
}
if msg.SubnetworkID != SubnetworkDAGCoin {
if msg.SubnetworkID != SubnetworkIDNative {
msg.Gas, err = binarySerializer.Uint64(r, littleEndian)
if err != nil {
returnScriptBuffers()
@ -601,8 +601,8 @@ func (msg *MsgTx) BtcEncode(w io.Writer, pver uint32) error {
return err
}
if msg.SubnetworkID != SubnetworkDAGCoin {
if msg.SubnetworkID == SubnetworkRegistry && msg.Gas != 0 {
if msg.SubnetworkID != SubnetworkIDNative {
if msg.SubnetworkID == SubnetworkIDRegistry && msg.Gas != 0 {
str := fmt.Sprintf("Transactions from subnetwork %v should have 0 gas", msg.SubnetworkID)
return messageError("MsgTx.BtcEncode", str)
}
@ -651,13 +651,13 @@ func (msg *MsgTx) Serialize(w io.Writer) error {
// SerializeSize returns the number of bytes it would take to serialize the
// the transaction.
func (msg *MsgTx) SerializeSize() int {
// Version 4 bytes + LockTime 8 bytes + Subnetwork ID 20
// Version 4 bytes + LockTime 8 bytes + SubnetworkID 20
// bytes + Serialized varint size for the number of transaction
// inputs and outputs.
n := 32 + VarIntSerializeSize(uint64(len(msg.TxIn))) +
VarIntSerializeSize(uint64(len(msg.TxOut)))
if msg.SubnetworkID != SubnetworkDAGCoin {
if msg.SubnetworkID != SubnetworkIDNative {
// Gas 8 bytes + Serialized varint size for the length of the payload
n += 8 + VarIntSerializeSize(uint64(len(msg.Payload)))
}
@ -735,13 +735,13 @@ func NewMsgTx(version int32) *MsgTx {
Version: version,
TxIn: make([]*TxIn, 0, defaultTxInOutAlloc),
TxOut: make([]*TxOut, 0, defaultTxInOutAlloc),
SubnetworkID: SubnetworkDAGCoin,
SubnetworkID: SubnetworkIDNative,
}
}
func newRegistryMsgTx(version int32, gasLimit uint64) *MsgTx {
tx := NewMsgTx(version)
tx.SubnetworkID = SubnetworkRegistry
tx.SubnetworkID = SubnetworkIDRegistry
tx.Payload = make([]byte, 8)
binary.LittleEndian.PutUint64(tx.Payload, gasLimit)
return tx

View File

@ -569,34 +569,34 @@ func TestTxSerializeErrors(t *testing.T) {
}
registryTx := NewMsgTx(1)
registryTx.SubnetworkID = SubnetworkRegistry
registryTx.SubnetworkID = SubnetworkIDRegistry
registryTx.Gas = 1
w := bytes.NewBuffer(make([]byte, 0, registryTx.SerializeSize()))
err := registryTx.Serialize(w)
str := fmt.Sprintf("Transactions from subnetwork %v should have 0 gas", SubnetworkRegistry)
str := fmt.Sprintf("Transactions from subnetwork %v should have 0 gas", SubnetworkIDRegistry)
expectedErr := messageError("MsgTx.BtcEncode", str)
if err == nil || err.Error() != expectedErr.Error() {
t.Errorf("TestTxSerializeErrors: expected error %v but got %v", expectedErr, err)
}
dagCoinTx := NewMsgTx(1)
dagCoinTx.Gas = 1
nativeTx := NewMsgTx(1)
nativeTx.Gas = 1
w = bytes.NewBuffer(make([]byte, 0, registryTx.SerializeSize()))
err = dagCoinTx.Serialize(w)
err = nativeTx.Serialize(w)
str = fmt.Sprintf("Transactions from subnetwork %v should have 0 gas", SubnetworkDAGCoin)
str = fmt.Sprintf("Transactions from subnetwork %v should have 0 gas", SubnetworkIDNative)
expectedErr = messageError("MsgTx.BtcEncode", str)
if err == nil || err.Error() != expectedErr.Error() {
t.Errorf("TestTxSerializeErrors: expected error %v but got %v", expectedErr, err)
}
dagCoinTx.Gas = 0
dagCoinTx.Payload = []byte{1, 2, 3}
nativeTx.Gas = 0
nativeTx.Payload = []byte{1, 2, 3}
w = bytes.NewBuffer(make([]byte, 0, registryTx.SerializeSize()))
err = dagCoinTx.Serialize(w)
err = nativeTx.Serialize(w)
str = fmt.Sprintf("Transactions from subnetwork %v should have <nil> payload", SubnetworkDAGCoin)
str = fmt.Sprintf("Transactions from subnetwork %v should have <nil> payload", SubnetworkIDNative)
expectedErr = messageError("MsgTx.BtcEncode", str)
if err == nil || err.Error() != expectedErr.Error() {
t.Errorf("TestTxSerializeErrors: expected error %v but got %v", expectedErr, err)
@ -619,7 +619,7 @@ func TestTxSerializeErrors(t *testing.T) {
var tx MsgTx
err = tx.Deserialize(r)
str = fmt.Sprintf("%v is a reserved sub network and cannot be used as part of a transaction", SubnetworkSupportsAll)
str = fmt.Sprintf("%v is a reserved sub network and cannot be used as part of a transaction", SubnetworkIDSupportsAll)
expectedErr = messageError("MsgTx.BtcDecode", str)
if err == nil || err.Error() != expectedErr.Error() {
t.Errorf("TestTxSerializeErrors: expected error %v but got %v", expectedErr, err)
@ -870,7 +870,7 @@ var multiTx = &MsgTx{
},
},
LockTime: 0,
SubnetworkID: SubnetworkDAGCoin,
SubnetworkID: SubnetworkIDNative,
}
// multiTxEncoded is the wire encoded bytes for multiTx using protocol version

View File

@ -58,7 +58,7 @@ type MsgVersion struct {
DisableRelayTx bool
// The subnetwork of the generator of the version message.
Subnetwork subnetworkid.SubnetworkID
SubnetworkID subnetworkid.SubnetworkID
}
// HasService returns whether the specified service is supported by the peer
@ -93,7 +93,7 @@ func (msg *MsgVersion) BtcDecode(r io.Reader, pver uint32) error {
return err
}
err = readElement(buf, &msg.Subnetwork)
err = readElement(buf, &msg.SubnetworkID)
if err != nil {
return err
}
@ -170,7 +170,7 @@ func (msg *MsgVersion) BtcEncode(w io.Writer, pver uint32) error {
return err
}
err = writeElement(w, msg.Subnetwork)
err = writeElement(w, msg.SubnetworkID)
if err != nil {
return err
}
@ -249,7 +249,7 @@ func NewMsgVersion(me *NetAddress, you *NetAddress, nonce uint64,
UserAgent: DefaultUserAgent,
LastBlock: lastBlock,
DisableRelayTx: false,
Subnetwork: *subnetworkID,
SubnetworkID: *subnetworkID,
}
}

View File

@ -32,7 +32,7 @@ func TestVersion(t *testing.T) {
}
// Ensure we get the correct data back out.
msg := NewMsgVersion(me, you, nonce, lastBlock, &SubnetworkSupportsAll)
msg := NewMsgVersion(me, you, nonce, lastBlock, &SubnetworkIDSupportsAll)
if msg.ProtocolVersion != int32(pver) {
t.Errorf("NewMsgVersion: wrong protocol version - got %v, want %v",
msg.ProtocolVersion, pver)
@ -289,7 +289,7 @@ func TestVersionWireErrors(t *testing.T) {
{baseVersion, baseVersionEncoded, pver, 4, io.ErrShortWrite, io.EOF},
// Force error in timestamp.
{baseVersion, baseVersionEncoded, pver, 12, io.ErrShortWrite, io.EOF},
// Force error in subnetwork.
// Force error in subnetworkID.
{baseVersion, baseVersionEncoded, pver, 20, io.ErrShortWrite, io.EOF},
// Force error in remote address.
{baseVersion, baseVersionEncoded, pver, 40, io.ErrShortWrite, io.EOF},
@ -487,7 +487,7 @@ var baseVersionEncoded = []byte{
0x29, 0xab, 0x5f, 0x49, 0x00, 0x00, 0x00, 0x00, // 64-bit Timestamp
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, // Subnetwork SupportsAll
0x00, 0x00, 0x00, 0x00, // SubnetworkIDSupportsAll
// AddrYou -- No timestamp for NetAddress in version message
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // SFNodeNetwork
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -536,7 +536,7 @@ var baseVersionBIP0037Encoded = []byte{
0x29, 0xab, 0x5f, 0x49, 0x00, 0x00, 0x00, 0x00, // 64-bit Timestamp
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, // Subnetwork SupportsAll
0x00, 0x00, 0x00, 0x00, // SubnetworkIDSupportsAll
// AddrYou -- No timestamp for NetAddress in version message
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // SFNodeNetwork
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,