diff --git a/build.gradle b/build.gradle index 5b6b81dbf..d806d1aef 100644 --- a/build.gradle +++ b/build.gradle @@ -22,6 +22,8 @@ dependencies { // Kotlin implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") implementation("org.jetbrains.kotlin:kotlin-reflect") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.2") + implementation("com.fasterxml.jackson.module:jackson-module-kotlin") implementation('com.fasterxml.jackson.datatype:jackson-datatype-jsr310') @@ -39,7 +41,7 @@ dependencies { // DB implementation('org.flywaydb:flyway-core') implementation('com.h2database:h2:2.1.210') - + implementation 'org.postgresql:postgresql:42.3.8' // Utils implementation('commons-net:commons-net:3.6') diff --git a/src/main/kotlin/io/openfuture/chain/consensus/service/DefaultEpochService.kt b/src/main/kotlin/io/openfuture/chain/consensus/service/DefaultEpochService.kt index b06cb9f58..7c1665736 100644 --- a/src/main/kotlin/io/openfuture/chain/consensus/service/DefaultEpochService.kt +++ b/src/main/kotlin/io/openfuture/chain/consensus/service/DefaultEpochService.kt @@ -7,7 +7,7 @@ import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @Service -@Transactional(readOnly = true) +@Transactional class DefaultEpochService( private val blockManager: BlockManager, private val properties: ConsensusProperties diff --git a/src/main/kotlin/io/openfuture/chain/core/model/entity/block/Block.kt b/src/main/kotlin/io/openfuture/chain/core/model/entity/block/Block.kt index 64a0c2e3a..5f77753eb 100644 --- a/src/main/kotlin/io/openfuture/chain/core/model/entity/block/Block.kt +++ b/src/main/kotlin/io/openfuture/chain/core/model/entity/block/Block.kt @@ -46,6 +46,23 @@ abstract class Block( return ByteUtils.toHexString(HashUtils.doubleSha256(bytes)) } + + fun generateHashForTransaction(timestamp: Long, + fee: Long, amount: Long, + senderAddress: String, + recipientAddress: String): String { + val bytes = ByteBuffer.allocate(SIZE_BYTES + SIZE_BYTES + SIZE_BYTES + + senderAddress.toByteArray().size + recipientAddress.toByteArray().size) + .putLong(timestamp) + .putLong(fee) + .put(senderAddress.toByteArray()) + .putLong(amount) + .put(recipientAddress.toByteArray()) + .array() + + return ByteUtils.toHexString(HashUtils.doubleSha256(bytes)) + } + } diff --git a/src/main/kotlin/io/openfuture/chain/core/service/block/DefaultBlockManager.kt b/src/main/kotlin/io/openfuture/chain/core/service/block/DefaultBlockManager.kt index 46d3214f1..195fc27b9 100644 --- a/src/main/kotlin/io/openfuture/chain/core/service/block/DefaultBlockManager.kt +++ b/src/main/kotlin/io/openfuture/chain/core/service/block/DefaultBlockManager.kt @@ -13,7 +13,7 @@ import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @Service -@Transactional(readOnly = true) +@Transactional class DefaultBlockManager( private val repository: BlockRepository, private val genesisBlockService: GenesisBlockService, diff --git a/src/main/kotlin/io/openfuture/chain/core/service/block/DefaultBlockService.kt b/src/main/kotlin/io/openfuture/chain/core/service/block/DefaultBlockService.kt index efbc1e42b..1c5e50ee1 100644 --- a/src/main/kotlin/io/openfuture/chain/core/service/block/DefaultBlockService.kt +++ b/src/main/kotlin/io/openfuture/chain/core/service/block/DefaultBlockService.kt @@ -9,7 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired import org.springframework.data.domain.Page import org.springframework.transaction.annotation.Transactional -@Transactional(readOnly = true) +@Transactional abstract class DefaultBlockService( private val repository: BlockRepository ) : BlockService { diff --git a/src/main/kotlin/io/openfuture/chain/core/service/block/DefaultGenesisBlockService.kt b/src/main/kotlin/io/openfuture/chain/core/service/block/DefaultGenesisBlockService.kt index 2c7bb5163..8b976e86e 100644 --- a/src/main/kotlin/io/openfuture/chain/core/service/block/DefaultGenesisBlockService.kt +++ b/src/main/kotlin/io/openfuture/chain/core/service/block/DefaultGenesisBlockService.kt @@ -20,7 +20,7 @@ import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @Service -@Transactional(readOnly = true) +@Transactional class DefaultGenesisBlockService( private val repository: GenesisBlockRepository, private val stateManager: StateManager, diff --git a/src/main/kotlin/io/openfuture/chain/core/service/block/DefaultMainBlockService.kt b/src/main/kotlin/io/openfuture/chain/core/service/block/DefaultMainBlockService.kt index 75e7f840f..dc5f218c8 100644 --- a/src/main/kotlin/io/openfuture/chain/core/service/block/DefaultMainBlockService.kt +++ b/src/main/kotlin/io/openfuture/chain/core/service/block/DefaultMainBlockService.kt @@ -37,7 +37,7 @@ import org.springframework.transaction.annotation.Transactional import kotlin.math.max @Service -@Transactional(readOnly = true) +@Transactional class DefaultMainBlockService( private val repository: MainBlockRepository, private val stateManager: StateManager, diff --git a/src/main/kotlin/io/openfuture/chain/core/service/block/validation/BlockValidator.kt b/src/main/kotlin/io/openfuture/chain/core/service/block/validation/BlockValidator.kt index 07e44700d..8bc99e1d6 100644 --- a/src/main/kotlin/io/openfuture/chain/core/service/block/validation/BlockValidator.kt +++ b/src/main/kotlin/io/openfuture/chain/core/service/block/validation/BlockValidator.kt @@ -13,7 +13,7 @@ import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.transaction.annotation.Transactional -@Transactional(readOnly = true) +@Transactional abstract class BlockValidator { companion object { diff --git a/src/main/kotlin/io/openfuture/chain/core/service/block/validation/MainBlockValidator.kt b/src/main/kotlin/io/openfuture/chain/core/service/block/validation/MainBlockValidator.kt index 34a5cbab3..f093e86db 100644 --- a/src/main/kotlin/io/openfuture/chain/core/service/block/validation/MainBlockValidator.kt +++ b/src/main/kotlin/io/openfuture/chain/core/service/block/validation/MainBlockValidator.kt @@ -25,7 +25,7 @@ import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @Service -@Transactional(readOnly = true) +@Transactional class MainBlockValidator( private val consensusProperties: ConsensusProperties, private val stateManager: StateManager, diff --git a/src/main/kotlin/io/openfuture/chain/core/service/receipt/DefaultReceiptService.kt b/src/main/kotlin/io/openfuture/chain/core/service/receipt/DefaultReceiptService.kt index 5e076b308..65cdcde44 100644 --- a/src/main/kotlin/io/openfuture/chain/core/service/receipt/DefaultReceiptService.kt +++ b/src/main/kotlin/io/openfuture/chain/core/service/receipt/DefaultReceiptService.kt @@ -12,7 +12,7 @@ import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @Service -@Transactional(readOnly = true) +@Transactional class DefaultReceiptService( private val repository: ReceiptRepository ) : ReceiptService { diff --git a/src/main/kotlin/io/openfuture/chain/core/service/state/DefaultAccountStateService.kt b/src/main/kotlin/io/openfuture/chain/core/service/state/DefaultAccountStateService.kt index 957c74007..275e2b7cc 100644 --- a/src/main/kotlin/io/openfuture/chain/core/service/state/DefaultAccountStateService.kt +++ b/src/main/kotlin/io/openfuture/chain/core/service/state/DefaultAccountStateService.kt @@ -10,7 +10,7 @@ import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @Service -@Transactional(readOnly = true) +@Transactional class DefaultAccountStateService( private val repository: AccountStateRepository, private val statePool: StatePool diff --git a/src/main/kotlin/io/openfuture/chain/core/service/state/DefaultDelegateStateService.kt b/src/main/kotlin/io/openfuture/chain/core/service/state/DefaultDelegateStateService.kt index 58e52c9c6..6082eaacd 100644 --- a/src/main/kotlin/io/openfuture/chain/core/service/state/DefaultDelegateStateService.kt +++ b/src/main/kotlin/io/openfuture/chain/core/service/state/DefaultDelegateStateService.kt @@ -13,7 +13,7 @@ import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @Service -@Transactional(readOnly = true) +@Transactional class DefaultDelegateStateService( private val repository: DelegateStateRepository, private val consensusProperties: ConsensusProperties, diff --git a/src/main/kotlin/io/openfuture/chain/core/service/state/DefaultStateManager.kt b/src/main/kotlin/io/openfuture/chain/core/service/state/DefaultStateManager.kt index cf265cabb..2af35ff5e 100644 --- a/src/main/kotlin/io/openfuture/chain/core/service/state/DefaultStateManager.kt +++ b/src/main/kotlin/io/openfuture/chain/core/service/state/DefaultStateManager.kt @@ -20,7 +20,7 @@ import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @Service -@Transactional(readOnly = true) +@Transactional class DefaultStateManager( private val repository: StateRepository, private val accountStateService: AccountStateService, diff --git a/src/main/kotlin/io/openfuture/chain/core/service/state/DefaultStateService.kt b/src/main/kotlin/io/openfuture/chain/core/service/state/DefaultStateService.kt index 1bb8c155d..675861edc 100644 --- a/src/main/kotlin/io/openfuture/chain/core/service/state/DefaultStateService.kt +++ b/src/main/kotlin/io/openfuture/chain/core/service/state/DefaultStateService.kt @@ -5,7 +5,7 @@ import io.openfuture.chain.core.repository.StateRepository import io.openfuture.chain.core.service.StateService import org.springframework.transaction.annotation.Transactional -@Transactional(readOnly = true) +@Transactional abstract class DefaultStateService( private val repository: StateRepository ) : StateService { diff --git a/src/main/kotlin/io/openfuture/chain/core/service/transaction/DefaultTransactionManager.kt b/src/main/kotlin/io/openfuture/chain/core/service/transaction/DefaultTransactionManager.kt index 5ececa362..018cb728c 100644 --- a/src/main/kotlin/io/openfuture/chain/core/service/transaction/DefaultTransactionManager.kt +++ b/src/main/kotlin/io/openfuture/chain/core/service/transaction/DefaultTransactionManager.kt @@ -20,7 +20,7 @@ import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @Service -@Transactional(readOnly = true) +@Transactional class DefaultTransactionManager( private val repository: TransactionRepository, private val uRepository: UTransactionRepository, diff --git a/src/main/kotlin/io/openfuture/chain/core/service/transaction/confirmed/DefaultDelegateTransactionService.kt b/src/main/kotlin/io/openfuture/chain/core/service/transaction/confirmed/DefaultDelegateTransactionService.kt index 2538d809c..048556042 100644 --- a/src/main/kotlin/io/openfuture/chain/core/service/transaction/confirmed/DefaultDelegateTransactionService.kt +++ b/src/main/kotlin/io/openfuture/chain/core/service/transaction/confirmed/DefaultDelegateTransactionService.kt @@ -11,7 +11,7 @@ import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @Service -@Transactional(readOnly = true) +@Transactional class DefaultDelegateTransactionService( private val repository: DelegateTransactionRepository, private val consensusProperties: ConsensusProperties diff --git a/src/main/kotlin/io/openfuture/chain/core/service/transaction/confirmed/DefaultExternalTransactionService.kt b/src/main/kotlin/io/openfuture/chain/core/service/transaction/confirmed/DefaultExternalTransactionService.kt index cbde330c7..1bb18f939 100644 --- a/src/main/kotlin/io/openfuture/chain/core/service/transaction/confirmed/DefaultExternalTransactionService.kt +++ b/src/main/kotlin/io/openfuture/chain/core/service/transaction/confirmed/DefaultExternalTransactionService.kt @@ -9,7 +9,7 @@ import io.openfuture.chain.core.service.ExternalTransactionService import org.springframework.beans.factory.annotation.Autowired import org.springframework.transaction.annotation.Transactional -@Transactional(readOnly = true) +@Transactional abstract class DefaultExternalTransactionService( private val repository: TransactionRepository ) : DefaultTransactionService(repository), ExternalTransactionService { diff --git a/src/main/kotlin/io/openfuture/chain/core/service/transaction/confirmed/DefaultRewardTransactionService.kt b/src/main/kotlin/io/openfuture/chain/core/service/transaction/confirmed/DefaultRewardTransactionService.kt index 437ba29a3..ab8f47af9 100644 --- a/src/main/kotlin/io/openfuture/chain/core/service/transaction/confirmed/DefaultRewardTransactionService.kt +++ b/src/main/kotlin/io/openfuture/chain/core/service/transaction/confirmed/DefaultRewardTransactionService.kt @@ -17,7 +17,7 @@ import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @Service -@Transactional(readOnly = true) +@Transactional class DefaultRewardTransactionService( private val repository: RewardTransactionRepository, private val consensusProperties: ConsensusProperties, diff --git a/src/main/kotlin/io/openfuture/chain/core/service/transaction/confirmed/DefaultTransactionService.kt b/src/main/kotlin/io/openfuture/chain/core/service/transaction/confirmed/DefaultTransactionService.kt index f8c744834..df7a4f251 100644 --- a/src/main/kotlin/io/openfuture/chain/core/service/transaction/confirmed/DefaultTransactionService.kt +++ b/src/main/kotlin/io/openfuture/chain/core/service/transaction/confirmed/DefaultTransactionService.kt @@ -12,7 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired import org.springframework.data.domain.Page import org.springframework.transaction.annotation.Transactional -@Transactional(readOnly = true) +@Transactional abstract class DefaultTransactionService( private val repository: TransactionRepository ) : TransactionService { diff --git a/src/main/kotlin/io/openfuture/chain/core/service/transaction/confirmed/DefaultTransferTransactionService.kt b/src/main/kotlin/io/openfuture/chain/core/service/transaction/confirmed/DefaultTransferTransactionService.kt index fe2500081..b9c9a9a4d 100644 --- a/src/main/kotlin/io/openfuture/chain/core/service/transaction/confirmed/DefaultTransferTransactionService.kt +++ b/src/main/kotlin/io/openfuture/chain/core/service/transaction/confirmed/DefaultTransferTransactionService.kt @@ -24,7 +24,7 @@ import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @Service -@Transactional(readOnly = true) +@Transactional class DefaultTransferTransactionService( private val repository: TransferTransactionRepository, private val contractService: ContractService, diff --git a/src/main/kotlin/io/openfuture/chain/core/service/transaction/confirmed/DefaultVoteTransactionService.kt b/src/main/kotlin/io/openfuture/chain/core/service/transaction/confirmed/DefaultVoteTransactionService.kt index 78afe457b..e9ef1404b 100644 --- a/src/main/kotlin/io/openfuture/chain/core/service/transaction/confirmed/DefaultVoteTransactionService.kt +++ b/src/main/kotlin/io/openfuture/chain/core/service/transaction/confirmed/DefaultVoteTransactionService.kt @@ -14,7 +14,7 @@ import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @Service -@Transactional(readOnly = true) +@Transactional class DefaultVoteTransactionService( private val repository: VoteTransactionRepository, private val consensusProperties: ConsensusProperties diff --git a/src/main/kotlin/io/openfuture/chain/core/service/transaction/unconfirmed/DefaultUDelegateTransactionService.kt b/src/main/kotlin/io/openfuture/chain/core/service/transaction/unconfirmed/DefaultUDelegateTransactionService.kt index 43d84096d..39b3eb8fe 100644 --- a/src/main/kotlin/io/openfuture/chain/core/service/transaction/unconfirmed/DefaultUDelegateTransactionService.kt +++ b/src/main/kotlin/io/openfuture/chain/core/service/transaction/unconfirmed/DefaultUDelegateTransactionService.kt @@ -8,7 +8,7 @@ import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @Service -@Transactional(readOnly = true) +@Transactional class DefaultUDelegateTransactionService( uRepository: UDelegateTransactionRepository, jdbcRepository: UTransactionsJdbcRepository diff --git a/src/main/kotlin/io/openfuture/chain/core/service/transaction/unconfirmed/DefaultUTransactionService.kt b/src/main/kotlin/io/openfuture/chain/core/service/transaction/unconfirmed/DefaultUTransactionService.kt index c493c34e5..72c777c83 100644 --- a/src/main/kotlin/io/openfuture/chain/core/service/transaction/unconfirmed/DefaultUTransactionService.kt +++ b/src/main/kotlin/io/openfuture/chain/core/service/transaction/unconfirmed/DefaultUTransactionService.kt @@ -24,7 +24,7 @@ import io.openfuture.chain.rpc.domain.base.PageRequest import org.springframework.beans.factory.annotation.Autowired import org.springframework.transaction.annotation.Transactional -@Transactional(readOnly = true) +@Transactional abstract class DefaultUTransactionService( private val uRepository: UTransactionRepository, private val jdbcRepository: UTransactionsJdbcRepository @@ -66,6 +66,7 @@ abstract class DefaultUTransactionService( @BlockchainSynchronized @Transactional + @Synchronized override fun add(uTx: uT, unconfirmedBalance: Long): uT { BlockchainLock.writeLock.lock() try { @@ -95,18 +96,27 @@ abstract class DefaultUTransactionService( else -> throw IllegalStateException("Wrong type") } + val findOneByHash = uRepository.findOneByHash(uTx.hash) + if (null != findOneByHash) { + print("Tried to save duplicate") + } + + val savedUtx = uRepository.saveAndFlush(uTx) + networkService.broadcast(savedUtx.toMessage()) + return savedUtx + // - return if (uTx is UnconfirmedTransferTransaction) { - val savedUtx = jdbcRepository.save(uTx) - networkService.broadcast(savedUtx.toMessage()) - uTx.id = savedUtx.id - return uTx - } else { - val savedUtx = uRepository.saveAndFlush(uTx) - networkService.broadcast(savedUtx.toMessage()) - savedUtx - } +// return if (uTx is UnconfirmedTransferTransaction) { +// val savedUtx = jdbcRepository.save(uTx) +// networkService.broadcast(savedUtx.toMessage()) +// uTx.id = savedUtx.id +// return uTx +// } else { +// val savedUtx = uRepository.saveAndFlush(uTx) +// networkService.broadcast(savedUtx.toMessage()) +// savedUtx +// } } finally { BlockchainLock.writeLock.unlock() diff --git a/src/main/kotlin/io/openfuture/chain/core/service/transaction/unconfirmed/DefaultUTransferTransactionService.kt b/src/main/kotlin/io/openfuture/chain/core/service/transaction/unconfirmed/DefaultUTransferTransactionService.kt index ef0675771..fdfed62b9 100644 --- a/src/main/kotlin/io/openfuture/chain/core/service/transaction/unconfirmed/DefaultUTransferTransactionService.kt +++ b/src/main/kotlin/io/openfuture/chain/core/service/transaction/unconfirmed/DefaultUTransferTransactionService.kt @@ -8,7 +8,7 @@ import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @Service -@Transactional(readOnly = true) +@Transactional class DefaultUTransferTransactionService( uRepository: UTransferTransactionRepository, jdbcRepository: UTransactionsJdbcRepository diff --git a/src/main/kotlin/io/openfuture/chain/core/service/transaction/unconfirmed/DefaultUVoteTransactionService.kt b/src/main/kotlin/io/openfuture/chain/core/service/transaction/unconfirmed/DefaultUVoteTransactionService.kt index 523a3c8a4..a88e39f8d 100644 --- a/src/main/kotlin/io/openfuture/chain/core/service/transaction/unconfirmed/DefaultUVoteTransactionService.kt +++ b/src/main/kotlin/io/openfuture/chain/core/service/transaction/unconfirmed/DefaultUVoteTransactionService.kt @@ -10,7 +10,7 @@ import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @Service -@Transactional(readOnly = true) +@Transactional class DefaultUVoteTransactionService( private val uRepository: UVoteTransactionRepository, jdbcRepository: UTransactionsJdbcRepository diff --git a/src/main/kotlin/io/openfuture/chain/core/service/transaction/validation/DelegateTransactionValidator.kt b/src/main/kotlin/io/openfuture/chain/core/service/transaction/validation/DelegateTransactionValidator.kt index 9cce6f7c5..7f3660a26 100644 --- a/src/main/kotlin/io/openfuture/chain/core/service/transaction/validation/DelegateTransactionValidator.kt +++ b/src/main/kotlin/io/openfuture/chain/core/service/transaction/validation/DelegateTransactionValidator.kt @@ -11,7 +11,7 @@ import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @Service -@Transactional(readOnly = true) +@Transactional class DelegateTransactionValidator( private val consensusProperties: ConsensusProperties, private val uRepository: UDelegateTransactionRepository diff --git a/src/main/kotlin/io/openfuture/chain/core/service/transaction/validation/RewardTransactionValidator.kt b/src/main/kotlin/io/openfuture/chain/core/service/transaction/validation/RewardTransactionValidator.kt index c6db513cf..e1ab2227f 100644 --- a/src/main/kotlin/io/openfuture/chain/core/service/transaction/validation/RewardTransactionValidator.kt +++ b/src/main/kotlin/io/openfuture/chain/core/service/transaction/validation/RewardTransactionValidator.kt @@ -5,7 +5,7 @@ import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @Service -@Transactional(readOnly = true) +@Transactional class RewardTransactionValidator : TransactionValidator() { fun check(): Array = arrayOf( diff --git a/src/main/kotlin/io/openfuture/chain/core/service/transaction/validation/TransactionValidator.kt b/src/main/kotlin/io/openfuture/chain/core/service/transaction/validation/TransactionValidator.kt index 5930b47f4..93929ce88 100644 --- a/src/main/kotlin/io/openfuture/chain/core/service/transaction/validation/TransactionValidator.kt +++ b/src/main/kotlin/io/openfuture/chain/core/service/transaction/validation/TransactionValidator.kt @@ -19,7 +19,7 @@ import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.transaction.annotation.Transactional -@Transactional(readOnly = true) +@Transactional abstract class TransactionValidator { @Autowired private lateinit var cryptoService: CryptoService diff --git a/src/main/kotlin/io/openfuture/chain/core/service/transaction/validation/TransferTransactionValidator.kt b/src/main/kotlin/io/openfuture/chain/core/service/transaction/validation/TransferTransactionValidator.kt index abfc6b3b8..2bfa2ca9c 100644 --- a/src/main/kotlin/io/openfuture/chain/core/service/transaction/validation/TransferTransactionValidator.kt +++ b/src/main/kotlin/io/openfuture/chain/core/service/transaction/validation/TransferTransactionValidator.kt @@ -15,7 +15,7 @@ import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @Service -@Transactional(readOnly = true) +@Transactional class TransferTransactionValidator( private val contractService: ContractService ) : TransactionValidator() { diff --git a/src/main/kotlin/io/openfuture/chain/core/service/transaction/validation/VoteTransactionValidator.kt b/src/main/kotlin/io/openfuture/chain/core/service/transaction/validation/VoteTransactionValidator.kt index 938600b7a..7928c2033 100644 --- a/src/main/kotlin/io/openfuture/chain/core/service/transaction/validation/VoteTransactionValidator.kt +++ b/src/main/kotlin/io/openfuture/chain/core/service/transaction/validation/VoteTransactionValidator.kt @@ -14,7 +14,7 @@ import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @Service -@Transactional(readOnly = true) +@Transactional class VoteTransactionValidator( private val consensusProperties: ConsensusProperties, private val uRepository: UVoteTransactionRepository diff --git a/src/main/kotlin/io/openfuture/chain/network/component/ChannelsHolder.kt b/src/main/kotlin/io/openfuture/chain/network/component/ChannelsHolder.kt index ebd2b51ad..5a88fd3ae 100644 --- a/src/main/kotlin/io/openfuture/chain/network/component/ChannelsHolder.kt +++ b/src/main/kotlin/io/openfuture/chain/network/component/ChannelsHolder.kt @@ -112,6 +112,7 @@ class ChannelsHolder( .minus(regularAddresses) val addresses = regularAddresses.plus(bootAddresses).shuffled() for (address in addresses) { + log.info("$addresses") val connected = connectionService.connect(address, Consumer { greet(it) }) diff --git a/src/main/kotlin/io/openfuture/chain/rpc/controller/base/ExceptionRestControllerAdvice.kt b/src/main/kotlin/io/openfuture/chain/rpc/controller/base/ExceptionRestControllerAdvice.kt index d1248ba71..3914c10f6 100644 --- a/src/main/kotlin/io/openfuture/chain/rpc/controller/base/ExceptionRestControllerAdvice.kt +++ b/src/main/kotlin/io/openfuture/chain/rpc/controller/base/ExceptionRestControllerAdvice.kt @@ -7,7 +7,6 @@ import io.openfuture.chain.core.exception.ValidationException import io.openfuture.chain.rpc.domain.ExceptionResponse import io.openfuture.chain.rpc.domain.ValidationErrorResponse import org.apache.commons.lang3.StringUtils.EMPTY -import org.h2.jdbc.JdbcSQLIntegrityConstraintViolationException import org.springframework.http.HttpStatus.BAD_REQUEST import org.springframework.http.HttpStatus.NOT_FOUND import org.springframework.web.bind.MethodArgumentNotValidException @@ -66,8 +65,8 @@ class ExceptionRestControllerAdvice { } @ResponseStatus(BAD_REQUEST) - @ExceptionHandler(JdbcSQLIntegrityConstraintViolationException::class) - fun handleJdbcSQLIntegrityConstraintViolationException(ex: JdbcSQLIntegrityConstraintViolationException): ExceptionResponse { + @ExceptionHandler(org.hibernate.exception.ConstraintViolationException::class) + fun handleJdbcSQLIntegrityConstraintViolationException(ex: org.hibernate.exception.ConstraintViolationException): ExceptionResponse { return ExceptionResponse(BAD_REQUEST.value(), ex.message) } diff --git a/src/main/kotlin/io/openfuture/chain/stresstest/TestController.kt b/src/main/kotlin/io/openfuture/chain/stresstest/TestController.kt new file mode 100644 index 000000000..7494de826 --- /dev/null +++ b/src/main/kotlin/io/openfuture/chain/stresstest/TestController.kt @@ -0,0 +1,208 @@ +package io.openfuture.chain.stresstest + +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import io.openfuture.chain.core.model.entity.block.Block +import io.openfuture.chain.crypto.util.SignatureUtils +import io.openfuture.chain.rpc.domain.RestResponse +import io.openfuture.chain.rpc.domain.transaction.request.TransferTransactionRequest +import kotlinx.coroutines.* +import org.bouncycastle.pqc.math.linearalgebra.ByteUtils +import org.springframework.validation.annotation.Validated +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RequestParam +import org.springframework.web.bind.annotation.RestController +import org.springframework.web.reactive.function.client.WebClient +import reactor.core.publisher.Mono +import java.util.concurrent.CountDownLatch + + +@RestController +@Validated +@RequestMapping("/rpc/test/transfer") +class TestController { + // private val concurrentRequests = 1 + private val coroutineScope = CoroutineScope(Dispatchers.Default) + private val hashes: MutableSet = hashSetOf() + private var requests: MutableSet = hashSetOf() + //private val latch = CountDownLatch(concurrentRequests) + + companion object { + private const val TRANSFER_TRANSACTION_URL = "/rpc/transactions/transfer" + private const val TRANSFER_TRANSACTION_GET_URL = "rpc/transactions/transfer/address/0x6f7c626D720044905536009AD0c637625e5F57F5?offset=0&limit=15&sortBy=timestamp&sortDirection=DESC" + } + + @GetMapping + fun test(@RequestParam(required = false) count: Int) : Long { + val latch = CountDownLatch(count) + val mapper = jacksonObjectMapper() + + /*val webClient = WebClient.builder().baseUrl("http://gunter.chain.openfuture.io:9090").build() + + val getListResponse = webClient.get() + .uri(TRANSFER_TRANSACTION_GET_URL) + .accept(MediaType.APPLICATION_JSON) + .retrieve() + .bodyToMono(RestResponse::class.java) + .block() + var initialTransactionCount = 0 + var finalTransactionCount = 0 + val javaType = mapper.typeFactory.constructParametricType(PageResponse::class.java, TransferTransactionResponse::class.java) + if (getListResponse != null) { + val respData: String = mapper.writeValueAsString(getListResponse.payload) + val pageResponseList: PageResponse = mapper.readValue(respData, javaType) + println("Total count : ${pageResponseList.totalCount}") + initialTransactionCount = pageResponseList.totalCount.toInt() + finalTransactionCount = initialTransactionCount + } + */ + val startTime = System.currentTimeMillis() + println("STARTED POST REQUEST") + + /* Flux.range(1, count) + .parallel() + .runOn(Schedulers.parallel()) + .flatMap { this.sendWebRequest(webClient) } + .doOnError{ + err -> println("WebClient err $err") + } + .subscribe()*/ + requests = hashSetOf() + val arrayListOf = arrayListOf() + for (i in 1..count) { + var createRandomTransferRequest = createRandomTransferRequest() + while (hashes.contains(createRandomTransferRequest.hash)) { + createRandomTransferRequest = createRandomTransferRequest() + } + hashes.add(createRandomTransferRequest.hash!!) + requests.add(createRandomTransferRequest) + } + println("Size: ${hashes.size}, distinct size: ${hashes.distinct().size}") + println(hashes) + + for (i in 1..count) { + coroutineScope.launch { + Thread.sleep(1000) + val request = requests.elementAt(i - 1) + + //println("Request $i request: $request in thread ${Thread.currentThread().name}") + val url = urlEndpoints.random() + println("THREAD ${Thread.currentThread().name} and url $url and hash ${request.hash}") + val webClient = WebClient.builder().baseUrl(url).build() + webClient.post() + .uri(TRANSFER_TRANSACTION_URL) + .body(Mono.just(request), TransferTransactionRequest::class.java) + .retrieve() + .bodyToMono(RestResponse::class.java) + .block() + + latch.countDown() + + } + } + latch.await() + println("ENDED POST REQUEST ${(System.currentTimeMillis()-startTime)/1000}") + //TODO - GET TIME TO UPDATE $concurrentRequests number of transactions to be updated + println("NUMBER OF TRANSACTIONS --- $count") + /*while (initialTransactionCount + count - 1 > finalTransactionCount){ + + val getListResponseFinal = webClient.get() + .uri(TRANSFER_TRANSACTION_GET_URL) + .accept(MediaType.APPLICATION_JSON) + .retrieve() + .bodyToMono(RestResponse::class.java) + .block() + + if (getListResponseFinal != null) { + val respData: String = mapper.writeValueAsString(getListResponseFinal.payload) + val pageResponseList: PageResponse = mapper.readValue(respData, javaType) + finalTransactionCount = pageResponseList.totalCount.toInt() + println("Current Transaction count : $finalTransactionCount") + val trxExecuted = (System.currentTimeMillis() - startTime)/1000 + val diff = finalTransactionCount - initialTransactionCount + println("Current processed transactions : $diff in - $trxExecuted") + if (diff > 1) + break + } + + Thread.sleep(10000) + } + val endTime = System.currentTimeMillis() + val executionTime = (endTime-startTime)/1000 + println("Time spent for confirmation : $executionTime seconds") + return executionTime*/ + return count.toLong() + } + + private fun createRandomTransferRequest(): TransferTransactionRequest { + val recipientAddress = recipientAddresses.random() + val timestamp = System.currentTimeMillis() + val hash = Block.generateHashForTransaction( + timestamp, + 0L, + 1L, + "0x6f7c626D720044905536009AD0c637625e5F57F5", + recipientAddress + ) + val privateKey = ByteUtils.fromHexString("3fd309d4e9ae09faf06aa49405ee296c0bae79ab862f26b638e3f638aba610f3") + val sign = SignatureUtils.sign(ByteUtils.fromHexString(hash), privateKey) + + return TransferTransactionRequest( + timestamp = timestamp, + fee = 0, + hash = hash, + senderAddress = "0x6f7c626D720044905536009AD0c637625e5F57F5", + senderSignature = sign, + senderPublicKey = "03609ceae592ac63503be363c99570da723bcb1e637c35c5a9044c78d826a3f79e", + amount = 1, + recipientAddress = recipientAddress, + data = null + ) + } + + private val recipientAddresses = listOf( + "0x523a4a63d1d3Aa7CEdbb7FB9d1363DE76DdBC2FD", + "0xE484275A491551de9944FAE8e9168bF5afA1Eb1e", + "0x523a4a63d1d3Aa7CEdbb7FB9d1363DE76DdBC2FD", + "0xE484275A491551de9944FAE8e9168bF5afA1Eb1e", + "0x49661d192C5Dd3C6097BF2edec5905cc6d691649", + "0x56e8DFcF58Af2922faf05fecd8F9c156B93C920f", + "0x8ADD8540CB4f474E4863455f7C7D2d876Ac84475", + "0xb1C95326174C06cafCa87140931918D522C501a7", + "0x4e93E5D112e878672888F5aE794287B28846f252", + "0x0A39e3C3dF795bd4Cd057A2fE381D2053eF84D7C", + "0xacD267a983c1A415DB0B96c62D443A9ba6C75B7E", + "0xe307b01801Ff02062aB3db937Ca0dAb836eC3EE0", + "0xb10A654bE8bb9144481Cb072053f5C11a81bC06e", + "0x55A763C173D3B77E2d00e8ED2Bb910E8c4a4308f", + "0xBD23fec0B69300bb18e2a82416A05ecFc9256D74", + "0x54466Ae803910baE12281bE814039F6457f95c62", + "0x875CEe49e89E963003E7C02a949Ca1BA0b0dA8b5", + "0x744e5f8Efb4dbfEC8b96F6429F9ce86904735736", + "0x604928a2A563748A1fFd2bFA670a2CEDb3445692", + "0xF5861731377be1b1736A29301f87C4Bf907895Db", + "0x175D5f7aC09D6f9c4B70C11b1cd84671bc3E9F0F", + "0xCd91F1eBb8E096dAAb1d5c2c97f5E340c6b2E155" + ) + + private val urlEndpoints = listOf( + "http://localhost:8082", + "http://localhost:8083" + ) + +// private val urlEndpoints = listOf( +// //"http://gunter.chain.openfuture.io:9090", +// "http://margo.chain.openfuture.io:9090", +// "http://wolf.chain.openfuture.io:9090", +// "http://charlie.chain.openfuture.io:9090", +// "http://gonzalez.chain.openfuture.io:9090", +// "http://george.chain.openfuture.io:9090", +// "http://pablo.chain.openfuture.io:9090", +// "http://anna.chain.openfuture.io:9090", +// "http://niko.chain.openfuture.io:9090", +// "http://bruce.chain.openfuture.io:9090", +// "http://chuck.chain.openfuture.io:9090") + + /*private val urlEndpoints = listOf( + "http://gunter.chain.openfuture.io:9090")*/ +} \ No newline at end of file diff --git a/src/main/resources/application-chain-1.properties b/src/main/resources/application-chain-1.properties index 27df89af7..2bf5ff9a1 100644 --- a/src/main/resources/application-chain-1.properties +++ b/src/main/resources/application-chain-1.properties @@ -1,9 +1,8 @@ # DATABASE -spring.datasource.driverClassName=org.h2.Driver -spring.datasource.url=jdbc:h2:./db/chain_1;NON_KEYWORDS=value,key,blocks,timestamp;DATABASE_TO_UPPER=false;FILE_LOCK=NO;LOCK_TIMEOUT=10000;DB_CLOSE_DELAY=-1;MODE=MYSQL -spring.jpa.open-in-view=true -spring.jpa.database-platform=org.hibernate.dialect.H2Dialect -spring.datasource.username=root +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_1 +spring.datasource.username=postgres spring.datasource.password=123456 # Logging @@ -14,6 +13,6 @@ server.port=8081 # NODE node.port=9191 -node.root-nodes=localhost:9192,localhost:9193,localhost:9194,localhost:9195 +node.root-nodes=localhost:9192,localhost:9193 -node.config-path=config-1.json \ No newline at end of file +node.config-path=configs/config-1.json \ No newline at end of file diff --git a/src/main/resources/application-chain-2.properties b/src/main/resources/application-chain-2.properties index 44b3092fa..49a849ce7 100644 --- a/src/main/resources/application-chain-2.properties +++ b/src/main/resources/application-chain-2.properties @@ -1,9 +1,8 @@ # DATABASE -spring.datasource.driverClassName=org.h2.Driver -spring.datasource.url=jdbc:h2:./db/chain_2;NON_KEYWORDS=value,key,blocks,timestamp;DATABASE_TO_UPPER=false;FILE_LOCK=NO;LOCK_TIMEOUT=10000;DB_CLOSE_DELAY=-1;MODE=MYSQL -spring.jpa.open-in-view=true -spring.jpa.database-platform=org.hibernate.dialect.H2Dialect -spring.datasource.username=root +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_2 +spring.datasource.username=postgres spring.datasource.password=123456 # Logging @@ -14,6 +13,6 @@ server.port=8082 # NODE node.port=9192 -node.root-nodes=localhost:9191,localhost:9193,localhost:9194,localhost:9195 +node.root-nodes=localhost:9191,localhost:9193 -node.config-path=config-2.json \ No newline at end of file +node.config-path=configs/config-2.json \ No newline at end of file diff --git a/src/main/resources/application-chain-3.properties b/src/main/resources/application-chain-3.properties index bd419c8d1..d08e29f5d 100644 --- a/src/main/resources/application-chain-3.properties +++ b/src/main/resources/application-chain-3.properties @@ -1,9 +1,8 @@ # DATABASE -spring.datasource.driverClassName=org.h2.Driver -spring.datasource.url=jdbc:h2:./db/chain_3;NON_KEYWORDS=value,key,blocks,timestamp;DATABASE_TO_UPPER=false;FILE_LOCK=NO;LOCK_TIMEOUT=10000;DB_CLOSE_DELAY=-1;MODE=MYSQL -spring.jpa.open-in-view=true -spring.jpa.database-platform=org.hibernate.dialect.H2Dialect -spring.datasource.username=root +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_3 +spring.datasource.username=postgres spring.datasource.password=123456 # Logging @@ -14,6 +13,6 @@ server.port=8083 # NODE node.port=9193 -node.root-nodes=localhost:9191,localhost:9192,localhost:9194,localhost:9195 +node.root-nodes=localhost:9191,localhost:9192 -node.config-path=config-3.json \ No newline at end of file +node.config-path=configs/config-3.json \ No newline at end of file diff --git a/src/main/resources/application-postgres.properties b/src/main/resources/application-postgres.properties new file mode 100644 index 000000000..7d2ac8caf --- /dev/null +++ b/src/main/resources/application-postgres.properties @@ -0,0 +1,18 @@ +# 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 + +# Logging +logging.level.io.openfuture.chain=INFO + +# RPC +server.port=8080 + +# NODE +node.port=9190 +node.root-nodes=localhost:9195 + +node.config-path=configs/config-5.json \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 2b56e35b3..b551d0957 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -29,7 +29,7 @@ node.peer-penalty=3600000 node.expiry=10000 node.sync-expiry=10000 node.sync-batch-size=22 -node.ntp-offset-threshold=100 +node.ntp-offset-threshold=1000 # CONSENSUS consensus.epoch-height=21 consensus.delegates-count=21 @@ -58,7 +58,6 @@ management.metrics.export.prometheus.step=15s #spring.jpa.properties.hibernate.generate_statistics=true ### HIKARI -spring.datasource.hikari.maximum-pool-size=90 spring.datasource.hikari.connectionTimeout=30000 spring.datasource.hikari.idleTimeout=600000 spring.datasource.hikari.maxLifetime=1800000 \ No newline at end of file diff --git a/src/main/resources/db/migration/V1_1__table_seed_words.sql b/src/main/resources/db/migration/V1_1__table_seed_words.sql index 4f9743598..277355de5 100644 --- a/src/main/resources/db/migration/V1_1__table_seed_words.sql +++ b/src/main/resources/db/migration/V1_1__table_seed_words.sql @@ -1,7 +1,8 @@ -CREATE TABLE seed_words ( - id BIGINT AUTO_INCREMENT PRIMARY KEY, - ind INTEGER NOT NULL UNIQUE, - value VARCHAR NOT NULL UNIQUE +CREATE TABLE seed_words +( + id serial PRIMARY KEY, + ind INTEGER NOT NULL UNIQUE, + value varchar(255) NOT NULL UNIQUE ); INSERT INTO seed_words (ind, value) diff --git a/src/main/resources/db/migration/V1_2__table_blocks.sql b/src/main/resources/db/migration/V1_2__table_blocks.sql index 8f38df86c..34256f3a9 100644 --- a/src/main/resources/db/migration/V1_2__table_blocks.sql +++ b/src/main/resources/db/migration/V1_2__table_blocks.sql @@ -1,37 +1,41 @@ -CREATE TABLE blocks ( - id BIGINT AUTO_INCREMENT PRIMARY KEY HASH, - timestamp BIGINT NOT NULL, - height BIGINT NOT NULL, - previous_hash VARCHAR NOT NULL, - hash VARCHAR NOT NULL, - signature VARCHAR NOT NULL, - public_key VARCHAR NOT NULL +CREATE TABLE blocks +( + id serial PRIMARY KEY, + timestamp BIGINT NOT NULL, + height BIGINT NOT NULL, + previous_hash text NOT NULL, + hash varchar(512) NOT NULL, + signature text NOT NULL, + public_key text NOT NULL ); -- -CREATE UNIQUE HASH INDEX blocks_hash - ON blocks (hash); +CREATE UNIQUE INDEX blocks_hash + ON blocks (hash); -- -CREATE UNIQUE HASH INDEX blocks_height - ON blocks (height); +CREATE UNIQUE INDEX blocks_height + ON blocks (height); -- -CREATE TABLE main_blocks ( - id BIGINT PRIMARY KEY REFERENCES blocks, - transaction_merkle_hash VARCHAR NOT NULL, - state_merkle_hash VARCHAR NOT NULL, - receipt_merkle_hash VARCHAR NOT NULL +CREATE TABLE main_blocks +( + id BIGINT PRIMARY KEY REFERENCES blocks, + transaction_merkle_hash text NOT NULL, + state_merkle_hash text NOT NULL, + receipt_merkle_hash text NOT NULL ); -- -CREATE TABLE genesis_blocks ( - id BIGINT PRIMARY KEY REFERENCES blocks, - epoch_index BIGINT NOT NULL +CREATE TABLE genesis_blocks +( + id BIGINT PRIMARY KEY REFERENCES blocks, + epoch_index BIGINT NOT NULL ); -- -CREATE HASH INDEX genesis_blocks_epoch_index - ON genesis_blocks (epoch_index); +CREATE INDEX genesis_blocks_epoch_index + ON genesis_blocks (epoch_index); -- -CREATE TABLE delegate2genesis ( - public_key VARCHAR NOT NULL, - genesis_id BIGINT NOT NULL REFERENCES genesis_blocks, - PRIMARY KEY (public_key, genesis_id) +CREATE TABLE delegate2genesis +( + public_key varchar(512) NOT NULL, + genesis_id BIGINT NOT NULL REFERENCES genesis_blocks, + PRIMARY KEY (public_key, genesis_id) ); \ No newline at end of file diff --git a/src/main/resources/db/migration/V1_3__table_transactions.sql b/src/main/resources/db/migration/V1_3__table_transactions.sql index bcec452c8..c09dac00b 100644 --- a/src/main/resources/db/migration/V1_3__table_transactions.sql +++ b/src/main/resources/db/migration/V1_3__table_transactions.sql @@ -1,110 +1,120 @@ -CREATE TABLE transactions ( - id BIGINT AUTO_INCREMENT PRIMARY KEY HASH, - timestamp BIGINT NOT NULL, - fee BIGINT NOT NULL, - sender_address VARCHAR NOT NULL, - hash VARCHAR NOT NULL, - signature VARCHAR NOT NULL, - sender_key VARCHAR NOT NULL, - block_id BIGINT NOT NULL REFERENCES main_blocks +CREATE TABLE transactions +( + id serial PRIMARY KEY, + timestamp BIGINT NOT NULL, + fee BIGINT NOT NULL, + sender_address varchar(512) NOT NULL, + hash varchar(512) NOT NULL, + signature text NOT NULL, + sender_key text NOT NULL, + block_id BIGINT NOT NULL REFERENCES main_blocks ); -- -CREATE UNIQUE HASH INDEX transaction_hash - ON transactions (hash); +CREATE UNIQUE INDEX transaction_hash + ON transactions (hash); -- -CREATE HASH INDEX transaction_sender_address - ON transactions (sender_address); +CREATE INDEX transaction_sender_address + ON transactions (sender_address); -- -CREATE TABLE transfer_transactions ( - id BIGINT PRIMARY KEY REFERENCES transactions, - amount BIGINT NOT NULL, - recipient_address VARCHAR, - data VARCHAR +CREATE TABLE transfer_transactions +( + id BIGINT PRIMARY KEY REFERENCES transactions, + amount BIGINT NOT NULL, + recipient_address varchar(512), + data text ); -- -CREATE HASH INDEX transfer_transaction_recipient_address - ON transfer_transactions (recipient_address); +CREATE INDEX transfer_transaction_recipient_address + ON transfer_transactions (recipient_address); -- -CREATE TABLE reward_transactions ( - id BIGINT PRIMARY KEY REFERENCES transactions, - reward BIGINT NOT NULL, - recipient_address VARCHAR NOT NULL +CREATE TABLE reward_transactions +( + id BIGINT PRIMARY KEY REFERENCES transactions, + reward BIGINT NOT NULL, + recipient_address varchar(512) NOT NULL ); -- -CREATE HASH INDEX reward_transactions_recipient_address - ON reward_transactions (recipient_address); +CREATE INDEX reward_transactions_recipient_address + ON reward_transactions (recipient_address); -- -CREATE TABLE delegate_transactions ( - id BIGINT PRIMARY KEY REFERENCES transactions, - delegate_key VARCHAR NOT NULL, - amount BIGINT NOT NULL +CREATE TABLE delegate_transactions +( + id BIGINT PRIMARY KEY REFERENCES transactions, + delegate_key varchar(512) NOT NULL, + amount BIGINT NOT NULL ); -- -CREATE UNIQUE HASH INDEX delegate_transactions_delegate_key - ON delegate_transactions (delegate_key); +CREATE UNIQUE INDEX delegate_transactions_delegate_key + ON delegate_transactions (delegate_key); -- -CREATE TABLE vote_types ( - id INTEGER AUTO_INCREMENT PRIMARY KEY HASH, - key VARCHAR NOT NULL UNIQUE +CREATE TABLE vote_types +( + id serial PRIMARY KEY, + key varchar(512) NOT NULL UNIQUE ); INSERT INTO vote_types (id, key) VALUES (1, 'FOR'), (2, 'AGAINST'); -- -CREATE TABLE vote_transactions ( - id BIGINT PRIMARY KEY REFERENCES transactions, - vote_type_id INTEGER NOT NULL REFERENCES vote_types, - delegate_key VARCHAR NOT NULL +CREATE TABLE vote_transactions +( + id BIGINT PRIMARY KEY REFERENCES transactions, + vote_type_id INTEGER NOT NULL REFERENCES vote_types, + delegate_key varchar(512) NOT NULL ); -- -CREATE HASH INDEX vote_transactions_delegate_key - ON vote_transactions (delegate_key); +CREATE INDEX vote_transactions_delegate_key + ON vote_transactions (delegate_key); -- -- UNCONFIRMED TABLES -CREATE MEMORY TABLE u_transactions ( - id BIGINT AUTO_INCREMENT PRIMARY KEY HASH, - timestamp BIGINT NOT NULL, - fee BIGINT NOT NULL, - sender_address VARCHAR NOT NULL, - hash VARCHAR NOT NULL, - signature VARCHAR NOT NULL, - sender_key VARCHAR NOT NULL +CREATE TABLE u_transactions +( + id serial PRIMARY KEY, + timestamp BIGINT NOT NULL, + fee BIGINT NOT NULL, + sender_address varchar(512) NOT NULL, + hash varchar(512) NOT NULL, + signature text NOT NULL, + sender_key text NOT NULL ); -- -CREATE UNIQUE HASH INDEX u_transactions_hash - ON u_transactions (hash); +CREATE UNIQUE INDEX u_transactions_hash + ON u_transactions (hash); -- -CREATE HASH INDEX u_transactions_sender_address - ON u_transactions (sender_address); +CREATE INDEX u_transactions_sender_address + ON u_transactions (sender_address); -- CREATE INDEX u_transactions_fee - ON u_transactions (fee); --- -CREATE MEMORY TABLE u_transfer_transactions ( - id BIGINT PRIMARY KEY REFERENCES u_transactions, - amount BIGINT NOT NULL, - recipient_address VARCHAR, - data VARCHAR + ON u_transactions (fee); +-- +CREATE TABLE u_transfer_transactions +( + id BIGINT PRIMARY KEY REFERENCES u_transactions, + amount BIGINT NOT NULL, + recipient_address text, + data text ); -- -CREATE MEMORY TABLE u_delegate_transactions ( - id BIGINT PRIMARY KEY REFERENCES u_transactions, - delegate_key VARCHAR NOT NULL, - amount BIGINT NOT NULL +CREATE TABLE u_delegate_transactions +( + id BIGINT PRIMARY KEY REFERENCES u_transactions, + delegate_key varchar(512) NOT NULL, + amount BIGINT NOT NULL ); -- -CREATE UNIQUE HASH INDEX u_delegate_transactions_delegate_key - ON u_delegate_transactions (delegate_key); +CREATE UNIQUE INDEX u_delegate_transactions_delegate_key + ON u_delegate_transactions (delegate_key); -- -CREATE MEMORY TABLE u_vote_transactions ( - id BIGINT PRIMARY KEY REFERENCES u_transactions, - vote_type_id INTEGER NOT NULL REFERENCES vote_types, - delegate_key VARCHAR NOT NULL +CREATE TABLE u_vote_transactions +( + id BIGINT PRIMARY KEY REFERENCES u_transactions, + vote_type_id INTEGER NOT NULL REFERENCES vote_types, + delegate_key varchar(512) NOT NULL ); -- CREATE INDEX u_vote_transactions_delegate_key - ON u_vote_transactions (delegate_key); + ON u_vote_transactions (delegate_key); -- \ No newline at end of file diff --git a/src/main/resources/db/migration/V1_4__table_states.sql b/src/main/resources/db/migration/V1_4__table_states.sql index 42ee998ff..a6d9bd564 100644 --- a/src/main/resources/db/migration/V1_4__table_states.sql +++ b/src/main/resources/db/migration/V1_4__table_states.sql @@ -1,22 +1,22 @@ CREATE TABLE states ( - id BIGINT AUTO_INCREMENT PRIMARY KEY HASH, - address VARCHAR NOT NULL, - hash VARCHAR NOT NULL + id serial PRIMARY KEY, + address varchar(512) NOT NULL, + hash varchar(512) NOT NULL ); -- -CREATE UNIQUE HASH INDEX states_address - ON states (address); +CREATE UNIQUE INDEX states_address + ON states (address); -- CREATE TABLE account_states ( - id BIGINT PRIMARY KEY REFERENCES states, - balance BIGINT NOT NULL, - vote_for VARCHAR, - storage VARCHAR + id BIGINT PRIMARY KEY REFERENCES states, + balance BIGINT NOT NULL, + vote_for text, + storage text ); -- CREATE TABLE delegate_states ( - id BIGINT PRIMARY KEY REFERENCES states, - rating BIGINT NOT NULL, - wallet_address VARCHAR NOT NULL, - create_date BIGINT NOT NULL + id BIGINT PRIMARY KEY REFERENCES states, + rating BIGINT NOT NULL, + wallet_address text NOT NULL, + create_date BIGINT NOT NULL ); \ No newline at end of file diff --git a/src/main/resources/db/migration/V1_5__table_contracts.sql b/src/main/resources/db/migration/V1_5__table_contracts.sql index 56b9174af..e54f88c0d 100644 --- a/src/main/resources/db/migration/V1_5__table_contracts.sql +++ b/src/main/resources/db/migration/V1_5__table_contracts.sql @@ -1,12 +1,12 @@ CREATE TABLE contracts ( - id BIGINT AUTO_INCREMENT PRIMARY KEY HASH, - address VARCHAR NOT NULL, - owner VARCHAR NOT NULL, - bytecode VARCHAR NOT NULL, - abi VARCHAR NOT NULL, - cost BIGINT NOT NULL + id serial PRIMARY KEY, + address varchar(512) NOT NULL, + owner text NOT NULL, + bytecode text NOT NULL, + abi text NOT NULL, + cost BIGINT NOT NULL ); -- -CREATE UNIQUE HASH INDEX contracts_address - ON contracts (address); +CREATE UNIQUE INDEX contracts_address + ON contracts (address); -- \ No newline at end of file diff --git a/src/main/resources/db/migration/V1_6__table_receipts.sql b/src/main/resources/db/migration/V1_6__table_receipts.sql index 2cdf23f84..7bc6686fb 100644 --- a/src/main/resources/db/migration/V1_6__table_receipts.sql +++ b/src/main/resources/db/migration/V1_6__table_receipts.sql @@ -1,11 +1,11 @@ CREATE TABLE receipts ( - id BIGINT AUTO_INCREMENT PRIMARY KEY HASH, - transaction_hash VARCHAR NOT NULL, - result VARCHAR NOT NULL, - hash VARCHAR NOT NULL, - block_id BIGINT NOT NULL REFERENCES main_blocks + id serial PRIMARY KEY, + transaction_hash varchar(512) NOT NULL, + result text NOT NULL, + hash text NOT NULL, + block_id BIGINT NOT NULL REFERENCES main_blocks ); -- -CREATE UNIQUE HASH INDEX receipts_transaction_hash - ON receipts (transaction_hash); +CREATE UNIQUE INDEX receipts_transaction_hash + ON receipts (transaction_hash); -- \ No newline at end of file diff --git a/src/main/resources/db/migration/V1_7__table_temporary_blocks.sql b/src/main/resources/db/migration/V1_7__table_temporary_blocks.sql index f93992866..9557570fa 100644 --- a/src/main/resources/db/migration/V1_7__table_temporary_blocks.sql +++ b/src/main/resources/db/migration/V1_7__table_temporary_blocks.sql @@ -1,6 +1,6 @@ CREATE TABLE temporary_blocks ( - id BIGINT AUTO_INCREMENT PRIMARY KEY HASH, - height BIGINT UNIQUE NOT NULL, - block VARCHAR NOT NULL + id serial PRIMARY KEY, + height BIGINT UNIQUE NOT NULL, + block text NOT NULL ); \ No newline at end of file