波场(java-tron)测试网络搭建

波场中文文档地址

波场(java-tron)测试网络搭建

由于某些原因,需要在内网环境下面搭建一个tron的网络,可以说是在内网中搭建一个基于tron的“主链”了。
准备

  1. 使用tron的Odyssey-3.6.5 分支
  2. 下载流程 略(自己用git也好,直接切换tag分支下载zip也行)
  3. 编译
    由于maven中的http请求去掉了,所以需要自己手动修改下 build.gradle文件 大概在 53行 修改如下(把url的http请求改成https)
repositories {
    mavenLocal()
    mavenCentral()
    maven { url 'https://repo.spring.io/plugins-release' }
}

然后执行 gradlew build 命令进行编译(不过建议加上 -x test参数 跳过测试,这样比较快)

./gradlew build -x test

4.编译成功后,会在java-tron/build/libs下,有六个Jar包,分别问 DBConvert.jar FullNode.jar java-tron-1.0.0.jar java-tron.jar KeystoreFactory.jar SolidityNode.jar
我们需要的是 FullNode.jar SolidityNode.jar java-tron.jar (这个java-tron.jar可以不要,我用它只是为了启动SuperNode节点,而SuperNode节点可以用FullNode.jar来代替)
机器地址说明
1、192.168.1.10 第一个超级节点搭建的机器
2、192.168.1.11 第二个超级节点搭建的机器

WitnessNode/SuperNode节点启动

注意,WitnessNode/SuperNode节点(两种叫法是同一个东西)的启动,需要区分“首个超级节点”以及“其它超级节点”。这两个节点的conf文件中的唯一区别就是 blick.needSyncCheck的不同

FirstWitness的conf文件片段
block = {
  needSyncCheck = false # first node : false, other : true
  maintenanceTimeInterval = 21600000 #// 1 day: 86400000(ms), 6 hours: 21600000(ms)
}

OtherSuperNode的conf文件片段
block = {
  needSyncCheck = true # first node : false, other : true
  maintenanceTimeInterval = 21600000 #// 1 day: 86400000(ms), 6 hours: 21600000(ms)
}

自己测试网络下的话,把其它的外网ip连接都删了,我这里的FistSuperNode.conf文件

net {
  type = mainnet
}

storage {
  # Directory for storing persistent data

  db.version = 2,
  db.engine = "LEVELDB",
  db.directory = "database",
  index.directory = "index",

  # Attention: name is a required field that must be set !!!
  properties = [
  ]

}

# this part of config is used to node discovery.
node.discovery = {
  enable = true  # you should set this entry value with ture if you want your node can be discovered by other node.
  persist = true  # this entry is used to determined to whether storing the peers in the database or not.
  bind.ip = ""
  external.ip = 127.0.0.1
}

# this part of config is used to set backup node for witness service.
node.backup {
  port = 10001
  priority = 8
  members = [
  ]
}

node {

  # expose extension api to public or not
  walletExtensionApi = true

  listen.port = 18888

  connection.timeout = 2

  tcpNettyWorkThreadNum = 0

  udpNettyWorkThreadNum = 1

  # Number of validate sign thread, default availableProcessors / 2
  # validateSignThreadNum = 16

  maxActiveNodes = 30

  maxActiveNodesWithSameIp = 2

  minParticipationRate = 0

  # check the peer data transfer ,disconnect factor
  disconnectNumberFactor = 0.4
  maxConnectNumberFactor = 0.8
  receiveTcpMinDataLength = 2048
  isOpenFullTcpDisconnect = true

  p2p {
    version = 123456
  }

  active = [
    "192.168.1.10:18888",
    "192.168.1.11:18888"
  ]

  passive = [
  ]

  http {
    fullNodePort = 8090
  }

  rpc {
    port = 10010

    # Connection being idle for longer than which will be gracefully terminated
    maxConnectionIdleInMillis = 60000

    # Transactions can only be broadcast if the number of effective connections is reached.
    minEffectiveConnection = 0
  }

}

seed.node = {
  ip.list = [
    "192.168.1.10:18888",
    "192.168.1.11:18888"
  ]
}

genesis.block = {
  # Reserve balance
  assets = [
    {
      accountName = "Zion"
      accountType = "AssetIssue"
      address = "TLLM21wteSPs4hKjbxgmH1L6poyMjeTbHm"
      balance = "99000000000000000"
    },
    {
      accountName = "Sun"
      accountType = "AssetIssue"
      address = "TXmVpin5vq5gdZsciyyjdZgKRUju4st1wM"
      balance = "0"
    },
    {
      accountName = "Blackhole"
      accountType = "AssetIssue"
      address = "TLsV52sRDL79HXGGm9yzwKibb6BeruhUzy"
      balance = "-9223372036854775808"
    },
    {
      accountName = "MyCoinCount"
      accountType = "AssetIssue"
      address = "TGVYyTXgkEh3aErPecHYeKjVTCSV9z3YUP"
      balance = "70000000000000"
    }
  ]

  witnesses = [
    {
      address: TG2AbfVs3cTAj9S51xvSNGPEJLGhAcCPQc,
      url = "http://192.168.1.10:18888",
      voteCount = 100000026
    },
    {
      address: TVYm1fdZJYaH3HrQEY9h2gygn3ZL9wrkPa,
      url = "http://192.168.1.11:18888",
      voteCount = 100000025
    }
  ]

  timestamp = "0" #2017-8-26 12:00:00

  parentHash = "0xe58f33f9baf9305dc6f82b9f1934ea8f0ade2defb951258d50167028c780351f"
}

localwitness = [
]

block = {
  needSyncCheck = false # first node : false, other : true
  maintenanceTimeInterval = 21600000 #// 1 day: 86400000(ms), 6 hours: 21600000(ms)
}

vm = {
  supportConstant = true
  minTimeRatio = 0.0
  maxTimeRatio = 5.0
}

committee = {
  allowCreationOfContracts = 1
}

启动方式:

nohup java -jar ./java-tron.jar -p <your-private-key>  -c <witness-node-config-file>  --witness 1>./console.log 2>&1 &

FullNode节点

参考的full.conf文件

net {
  type = mainnet
}

storage {
  # Directory for storing persistent data

  db.version = 2,
  db.engine = "LEVELDB",
  db.directory = "database",
  index.directory = "index",

  # Attention: name is a required field that must be set !!!
  properties = [
  ]

}

# this part of config is used to node discovery.
node.discovery = {
  enable = true  # you should set this entry value with ture if you want your node can be discovered by other node.
  persist = true  # this entry is used to determined to whether storing the peers in the database or not.
  bind.ip = ""
  external.ip = 127.0.0.1
}

# this part of config is used to set backup node for witness service.
node.backup {
  port = 10001
  priority = 8
  members = [
  ]
}

node {

  listen.port = 20017

  connection.timeout = 2

  tcpNettyWorkThreadNum = 0

  udpNettyWorkThreadNum = 1

  # Number of validate sign thread, default availableProcessors / 2
  # validateSignThreadNum = 16

  maxActiveNodes = 30

  maxActiveNodesWithSameIp = 2

  minParticipationRate = 0

  # check the peer data transfer ,disconnect factor
  disconnectNumberFactor = 0.4
  maxConnectNumberFactor = 0.8
  receiveTcpMinDataLength = 2048
  isOpenFullTcpDisconnect = true

  p2p {
    version = 123456
  }

  active = [
    "192.168.1.10:18888",
    "192.168.1.11:18888"
  ]

  passive = [
  ]

  http {
    fullNodePort = 8096
  }

  rpc {
    port = 10021

    # Connection being idle for longer than which will be gracefully terminated
    maxConnectionIdleInMillis = 60000

    # Transactions can only be broadcast if the number of effective connections is reached.
    minEffectiveConnection = 0
  }

}

seed.node = {
  ip.list = [
    "192.168.1.10:18888",
    "192.168.1.11:18888"
  ]
}

genesis.block = {
  # Reserve balance
  assets = [
    {
      accountName = "Zion"
      accountType = "AssetIssue"
      address = "TLLM21wteSPs4hKjbxgmH1L6poyMjeTbHm"
      balance = "99000000000000000"
    },
    {
      accountName = "Sun"
      accountType = "AssetIssue"
      address = "TXmVpin5vq5gdZsciyyjdZgKRUju4st1wM"
      balance = "0"
    },
    {
      accountName = "Blackhole"
      accountType = "AssetIssue"
      address = "TLsV52sRDL79HXGGm9yzwKibb6BeruhUzy"
      balance = "-9223372036854775808"
    },
    {
      accountName = "HOMECOIN"
      accountType = "AssetIssue"
      address = "TGVYyTXgkEh3aErPecHYeKjVTCSV9z3YUP"
      balance = "70000000000000"
    }
  ]

  witnesses = [
    {
      address: TG2AbfVs3cTAj9S51xvSNGPEJLGhAcCPQc,
      url = "http://192.168.1.10:18888",
      voteCount = 100000026
    },
    {
      address: TVYm1fdZJYaH3HrQEY9h2gygn3ZL9wrkPa,
      url = "http://192.168.1.11:18888",
      voteCount = 100000025
    }
  ]

  timestamp = "0" #2017-8-26 12:00:00

  parentHash = "0xe58f33f9baf9305dc6f82b9f1934ea8f0ade2defb951258d50167028c780351f"
}

localwitness = [
]

block = {
  needSyncCheck = true # first node : false, other : true
  maintenanceTimeInterval = 21600000 #// 1 day: 86400000(ms), 6 hours: 21600000(ms)
}

启动方法

nohup java -jar ./FullNode.jar -c full.conf 1>/dev/null 2>&1 &

SolidityNode启动

一般来说,我们可以在FullNode节点所在的机器再搭建一个SolidityNode(如果不是这样的话,我们就要把solidity.conf中的node.trustNode修改成对应的FullNode对应的地址)
solidity.conf文件配置

net {
  type = mainnet
}

storage {
  # Directory for storing persistent data

  db.version = 2,
  db.engine = "LEVELDB",
  db.directory = "database",
  index.directory = "index",

  # Attention: name is a required field that must be set !!!
  properties = [
  ]

}

# this part of config is used to node discovery.
node.discovery = {
  enable = true  # you should set this entry value with ture if you want your node can be discovered by other node.
  persist = true  # this entry is used to determined to whether storing the peers in the database or not.
  bind.ip = ""
  external.ip = 127.0.0.1
}

# this part of config is used to set backup node for witness service.
node.backup {
  port = 10001
  priority = 8
  members = [
  ]
}

node {
  # trust node for solidity node
  # trustNode = "ip:port"
  trustNode = "127.0.0.1:10021"

  # expose extension api to public or not
  walletExtensionApi = true

  listen.port = 20018

  connection.timeout = 2

  tcpNettyWorkThreadNum = 0

  udpNettyWorkThreadNum = 1

  maxActiveNodes = 30

  maxActiveNodesWithSameIp = 2

  minParticipationRate = 0

  # check the peer data transfer ,disconnect factor
  disconnectNumberFactor = 0.4
  maxConnectNumberFactor = 0.8
  receiveTcpMinDataLength = 2048
  isOpenFullTcpDisconnect = true

  p2p {
    version = 123456
  }

  active = [
        "127.0.0.1:20017"
  ]

  passive = [
  ]

  http {
    solidityPort = 8097
  }

  rpc {
    port = 10022

    # Connection being idle for longer than which will be gracefully terminated
    maxConnectionIdleInMillis = 60000

    # Transactions can only be broadcast if the number of effective connections is reached.
    minEffectiveConnection = 0
  }
}

seed.node = {
  ip.list = [
  ]
}
genesis.block = {
  # Reserve balance
  assets = [
    {
      accountName = "Zion"
      accountType = "AssetIssue"
      address = "TLLM21wteSPs4hKjbxgmH1L6poyMjeTbHm"
      balance = "99000000000000000"
    },
    {
      accountName = "Sun"
      accountType = "AssetIssue"
      address = "TXmVpin5vq5gdZsciyyjdZgKRUju4st1wM"
      balance = "0"
    },
    {
      accountName = "Blackhole"
      accountType = "AssetIssue"
      address = "TLsV52sRDL79HXGGm9yzwKibb6BeruhUzy"
      balance = "-9223372036854775808"
    },
    {
      accountName = "HOMECOIN"
      accountType = "AssetIssue"
      address = "TGVYyTXgkEh3aErPecHYeKjVTCSV9z3YUP"
      balance = "70000000000000"
    }
  ]

  witnesses = [
    {
      address: TG2AbfVs3cTAj9S51xvSNGPEJLGhAcCPQc,
      url = "http://192.168.1.10:18888",
      voteCount = 100000026
    },
    {
      address: TVYm1fdZJYaH3HrQEY9h2gygn3ZL9wrkPa,
      url = "http://192.168.1.11:18888",
      voteCount = 100000025
    }
  ]

  timestamp = "0" #2017-8-26 12:00:00

  parentHash = "0xe58f33f9baf9305dc6f82b9f1934ea8f0ade2defb951258d50167028c780351f"
}

localwitness = [
]

block = {
  needSyncCheck = true # first node : false, other : true
  maintenanceTimeInterval = 21600000 #// 1 day: 86400000(ms), 6 hours: 21600000(ms)
}

启动方法:

nohup java -jar ./SolidityNode.jar -c solidity.conf 1>/dev/null 2>&1 &

此外,搭建自己的节点,需要自己修改genesis.block.assets下面的地址,同时备份好对应的秘钥
生成地址&加密文件&秘钥 可以通过KeystoreFactory.jar工具

请求接口(验证是否成功。这里以查询最新块来验证)

Witness
curl -X POST  http://192.168.0.10:8095/wallet/getnowblock
curl -X POST  http://192.168.0.11:8095/wallet/getnowblock

full:
curl -X POST  http://192.168.0.20:8096/wallet/getnowblock
solidity:
curl -X POST  http://192.168.0.20:8097/walletsolidity/getnowblock

猜你喜欢

转载自blog.csdn.net/sail331x/article/details/106074146