Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sa 93 start new chain network from open chain #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,4 @@ jacocoTestReport {
html.enabled = true
}
}
check.dependsOn jacocoTestReport

// Front
processResources.dependsOn(':frontend:assemble')
check.dependsOn jacocoTestReport
2 changes: 1 addition & 1 deletion chain-kotlin-sdk
Submodule chain-kotlin-sdk updated from 4dd977 to fff334
6 changes: 6 additions & 0 deletions config-1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"externalPort" : 9191,
"externalHost" : "127.0.0.1",
"secret" : "89f0667fe951f77fdce8d840683c34cfe21c5e17c6c4d55a5786903d137ef076",
"mode" : "FULL"
}
6 changes: 6 additions & 0 deletions config-2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"externalPort" : 9192,
"externalHost" : "127.0.0.1",
"secret" : "dac3fb2d3c40502406a43ddc849aae7085fcaf68cd5ef68a19a3ea855a4fd353",
"mode" : "FULL"
}
6 changes: 6 additions & 0 deletions config-3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"externalPort" : 9193,
"externalHost" : "127.0.0.1",
"secret" : "dab92166513f2bfaaf8c75cf6a9803e683574445f65461f477714e95b3ba3906",
"mode" : "FULL"
}
6 changes: 6 additions & 0 deletions config-4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"externalPort" : 9194,
"externalHost" : "127.0.0.1",
"secret" : "afc442a5eb0253dce40e3a25596ab8ba5ec8b043dd99826b28b271594e4367c6",
"mode" : "FULL"
}
6 changes: 6 additions & 0 deletions config-5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"externalPort" : 9195,
"externalHost" : "127.0.0.1",
"secret" : "b2429c16c9afa2d7f5a5de3b90ef3a9ed536a233aeedc37c6a110093edfb7d09",
"mode" : "FULL"
}
6 changes: 6 additions & 0 deletions config-6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"externalPort" : 9196,
"externalHost" : "127.0.0.1",
"secret" : "90434d590f3f11af3bdefd517b7f20bced148f10d57925aa665771c01e3f1b4a",
"mode" : "LIGHT"
}
18 changes: 18 additions & 0 deletions dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

1.
chronic rival prosper lamp leader wood dizzy december iron confirm source express
private key: 89f0667fe951f77fdce8d840683c34cfe21c5e17c6c4d55a5786903d137ef076
address: 0xEA1b30BD5Ba790787dd795Ec5cdb815E43958681
public key: 03ae0cfa7f1664d02cd4f95b0ee0397c3b37b860106ab7e62bbd45e357d43a4cb6

2.
aerobic dove pelican hire square apple satisfy dove casual lonely calm rebel
private key: dac3fb2d3c40502406a43ddc849aae7085fcaf68cd5ef68a19a3ea855a4fd353
public key: 03f3ae70cb893a1b218e008cf79ee6a5ee69f4d93b6342b676ff1bfd64310e06eb
address: 0xb6D847780B3736362f12eB46bf043C11c0028135

3.
rural wrestle library cinnamon give broccoli upgrade license doll wear abuse menu
private key: dab92166513f2bfaaf8c75cf6a9803e683574445f65461f477714e95b3ba3906
public key: 03a0ed2889f622a425f7a2ee4333ffe889d79120e476751ee2f1be4e2a82d57e46
address: 0x23f340F3E78A4BD302B73f622DB4d0631DbFef03
1 change: 0 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
rootProject.name = 'open-chain'

include('frontend')
includeBuild('./chain-kotlin-sdk')
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,8 @@ class MainBlockPayload(
override fun getBytes(): ByteArray =
transactionMerkleHash.toByteArray() + stateMerkleHash.toByteArray() + receiptMerkleHash.toByteArray()

fun hasTransferTransactions(): Boolean = transferTransactions.isNotEmpty()

fun hasVoteTransactions(): Boolean = voteTransactions.isNotEmpty()

}
Original file line number Diff line number Diff line change
Expand Up @@ -125,37 +125,43 @@ class MainBlockValidator(

fun checkReceiptsAndStates(): BlockValidateHandler = { block, _, _, new ->
block as MainBlock
val blockStates = block.getPayload().delegateStates + block.getPayload().accountStates
val payload = block.getPayload()
val blockStates = payload.delegateStates + payload.accountStates

blockStates.forEach {
if (!stateManager.verify(it)) {
throw ValidationException("Invalid block states in block: height #${block.height}, hash ${block.hash}")
}
}

block.getPayload().receipts.forEach {
payload.receipts.forEach {
if (!receiptService.verify(it)) {
throw ValidationException("Invalid block receipts in block: height #${block.height}, hash ${block.hash}")
}
}

if (new) {
val delegateWallet = stateManager.getByAddress<DelegateState>(block.publicKey).walletAddress
val transactions = block.getPayload().delegateTransactions + block.getPayload().transferTransactions +
block.getPayload().voteTransactions + block.getPayload().rewardTransactions
val transactions = payload.delegateTransactions + payload.transferTransactions +
payload.voteTransactions + payload.rewardTransactions
val receipts = transactionManager.processTransactions(transactions, delegateWallet)
val states = statePool.getStates()

if (block.getPayload().receipts.size != receipts.size) {
if (payload.receipts.size != receipts.size) {
throw ValidationException("Invalid count block receipts in block: height #${block.height}, hash ${block.hash}")
}

if (!payload.hasTransferTransactions() && !payload.hasVoteTransactions()) {
throw ValidationException("Block won't be created due to: has transfer transactions: " +
"${payload.hasTransferTransactions()} has vote transactions: ${payload.hasVoteTransactions()}")
}

if (blockStates.size != states.size) {
throw ValidationException("Invalid count block states in block: height #${block.height}, hash ${block.hash}")
}

receipts.forEach { r ->
block.getPayload().receipts.firstOrNull { it.hash == r.hash }
payload.receipts.firstOrNull { it.hash == r.hash }
?: throw ValidationException("Invalid block receipts in block: height #${block.height}, hash ${block.hash}")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class DefaultStateManager(
override fun commit(states: List<State>) {
BlockchainLock.writeLock.lock()
try {
states.forEach { println(it.address) }
repository.deleteAllByAddressIn(states.map { it.address })
repository.flush()
repository.saveAll(states)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ data class NodeInfo(

override fun read(buf: ByteBuf) {
uid = buf.readString()
address = NetworkAddress::class.java.newInstance()
address = NetworkAddress::class.java.getDeclaredConstructor().newInstance()
address.read(buf)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ inline fun <reified T : Message> ByteBuf.readList(): MutableList<T> {
val size = this.readInt()
val list = mutableListOf<T>()
for (index in 1..size) {
val instance = T::class.java.newInstance()
val instance = T::class.java.getDeclaredConstructor().newInstance()
instance.read(this)
list.add(instance)
}
Expand All @@ -55,7 +55,7 @@ inline fun <reified T : Message> ByteBuf.readSet(): MutableSet<T> {
val size = this.readInt()
val set = mutableSetOf<T>()
for (index in 1..size) {
val instance = T::class.java.newInstance()
val instance = T::class.java.getDeclaredConstructor().newInstance()
instance.read(this)
set.add(instance)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ class ClientChannelInitializer(
epochResponseHandler,
mainBlockHandler,
genesisBlockHandler,

blockAvailabilityRequestHandler,
blockAvailabilityResponseHandler,
syncStatusHandler,
blockAvailabilityRequestHandler,
// core
transferTransactionHandler,
delegateTransactionHandler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ class ServerChannelInitializer(
epochResponseHandler,
mainBlockHandler,
genesisBlockHandler,
blockAvailabilityRequestHandler,
blockAvailabilityResponseHandler,
syncStatusHandler,
blockAvailabilityRequestHandler,
// core
transferTransactionHandler,
delegateTransactionHandler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class BlockAvailabilityResponse(
hash = buf.readString()
height = buf.readLong()
if (-1L != height) {
val block = GenesisBlockMessage::class.java.newInstance()
val block = GenesisBlockMessage::class.java.getDeclaredConstructor().newInstance()
block.read(buf)
genesisBlock = block
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ data class NewClient(
) : Message {

override fun read(buf: ByteBuf) {
nodeInfo = NodeInfo::class.java.newInstance()
nodeInfo = NodeInfo::class.java.getDeclaredConstructor().newInstance()
nodeInfo.read(buf)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object SmartContractInjector {


fun initSmartContract(clazz: Class<*>, owner: String, address: String): SmartContract {
val instance = clazz.newInstance() as SmartContract
val instance = clazz.getDeclaredConstructor().newInstance() as SmartContract

injectField(instance, OWNER_FIELD, owner)
injectField(instance, ADDRESS_FIELD, address)
Expand Down
18 changes: 18 additions & 0 deletions src/main/resources/application-chain-1.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# DATABASE
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.url=jdbc:h2:./db/chain-1;MV_STORE=FALSE;MVCC=FALSE;FILE_LOCK=NO;LOCK_TIMEOUT=10000;DB_CLOSE_DELAY=-1
spring.datasource.username=root
spring.datasource.password=123456
spring.jpa.open-in-view=true

# Logging
logging.level.io.openfuture.chain=INFO

# RPC
server.port=8081

# NODE
node.port=9191
node.root-nodes=localhost:9192,localhost:9193,localhost:9194,localhost:9195

node.config-path=config-1.json
18 changes: 18 additions & 0 deletions src/main/resources/application-chain-2.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# DATABASE
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.url=jdbc:h2:./db/chain-2;MV_STORE=FALSE;MVCC=FALSE;FILE_LOCK=NO;LOCK_TIMEOUT=10000;DB_CLOSE_DELAY=-1
spring.datasource.username=root
spring.datasource.password=123456
spring.jpa.open-in-view=true

# Logging
logging.level.io.openfuture.chain=INFO

# RPC
server.port=8082

# NODE
node.port=9192
node.root-nodes=localhost:9191,localhost:9193,localhost:9194,localhost:9195

node.config-path=config-2.json
18 changes: 18 additions & 0 deletions src/main/resources/application-chain-3.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# DATABASE
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.url=jdbc:h2:./db/chain-3;MV_STORE=FALSE;MVCC=FALSE;FILE_LOCK=NO;LOCK_TIMEOUT=10000;DB_CLOSE_DELAY=-1
spring.datasource.username=root
spring.datasource.password=123456
spring.jpa.open-in-view=true

# Logging
logging.level.io.openfuture.chain=INFO

# RPC
server.port=8083

# NODE
node.port=9193
node.root-nodes=localhost:9191,localhost:9192,localhost:9194,localhost:9195

node.config-path=config-3.json
18 changes: 18 additions & 0 deletions src/main/resources/application-chain-4.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# DATABASE
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.url=jdbc:h2:./db/chain-4;MV_STORE=FALSE;MVCC=FALSE;FILE_LOCK=NO;LOCK_TIMEOUT=10000;DB_CLOSE_DELAY=-1
spring.datasource.username=root
spring.datasource.password=123456
spring.jpa.open-in-view=true

# Logging
logging.level.io.openfuture.chain=INFO

# RPC
server.port=8084

# NODE
node.port=9194
node.root-nodes=localhost:9191,localhost:9192,localhost:9193,localhost:9195

node.config-path=config-4.json
18 changes: 18 additions & 0 deletions src/main/resources/application-chain-5.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# DATABASE
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.url=jdbc:h2:./db/chain-5;MV_STORE=FALSE;MVCC=FALSE;FILE_LOCK=NO;LOCK_TIMEOUT=10000;DB_CLOSE_DELAY=-1
spring.datasource.username=root
spring.datasource.password=123456
spring.jpa.open-in-view=true

# Logging
logging.level.io.openfuture.chain=INFO

# RPC
server.port=8085

# NODE
node.port=9195
node.root-nodes=localhost:9191,localhost:9192,localhost:9193,localhost:9194

node.config-path=config-5.json
18 changes: 18 additions & 0 deletions src/main/resources/application-chain-6.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# DATABASE
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.url=jdbc:h2:./db/chain-6;MV_STORE=FALSE;MVCC=FALSE;FILE_LOCK=NO;DB_CLOSE_DELAY=-1
spring.jpa.open-in-view=true
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect

# Logging
logging.level.io.openfuture.chain=INFO

# RPC
server.port=8086

# NODE
node.port=9196
node.root-nodes=localhost:9191,locahost:8081,localhost:9192,locahost:8082,localhost:9193,locahost:8083,localhost:9194,locahost:8084,localhost:9195,locahost:8085,localhost:9199,\
locahost:8089

node.config-path=config-6.json
18 changes: 18 additions & 0 deletions src/main/resources/application-chain-mysql.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# DATABASE
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3308/local_db?allowPublicKeyRetrieval=true&useSSL=false
spring.datasource.username=root
spring.datasource.password=123456
spring.jpa.open-in-view=true

# Logging
logging.level.io.openfuture.chain=DEBUG

# RPC
server.port=8081

# NODE
node.port=9191
node.root-nodes=localhost:9192,localhost:9193

node.config-path=config-1.json
19 changes: 19 additions & 0 deletions src/main/resources/application-chain-postgres.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# DATABASE
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.datasource.url=jdbc:postgresql://localhost:5434/open_chain
spring.datasource.username=postgres
spring.datasource.password=123456
spring.jpa.open-in-view=true

# Logging
logging.level.io.openfuture.chain=INFO

# RPC
server.port=8081

# NODE
node.port=9191
node.root-nodes=localhost:9195,locahost:8085,localhost:9192,locahost:8082,localhost:9193,locahost:8083,localhost:9194,locahost:8084

node.config-path=config-1.json
Loading