Skip to content

Commit 38f9dda

Browse files
author
Beksultan
committed
Sprint
1 parent 0fb5166 commit 38f9dda

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+463
-197
lines changed

build.gradle

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ dependencies {
2222
// Kotlin
2323
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
2424
implementation("org.jetbrains.kotlin:kotlin-reflect")
25+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.2")
26+
2527
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
2628
implementation('com.fasterxml.jackson.datatype:jackson-datatype-jsr310')
2729

@@ -39,7 +41,7 @@ dependencies {
3941
// DB
4042
implementation('org.flywaydb:flyway-core')
4143
implementation('com.h2database:h2:2.1.210')
42-
44+
implementation 'org.postgresql:postgresql:42.3.8'
4345

4446
// Utils
4547
implementation('commons-net:commons-net:3.6')

src/main/kotlin/io/openfuture/chain/consensus/service/DefaultEpochService.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import org.springframework.stereotype.Service
77
import org.springframework.transaction.annotation.Transactional
88

99
@Service
10-
@Transactional(readOnly = true)
10+
@Transactional
1111
class DefaultEpochService(
1212
private val blockManager: BlockManager,
1313
private val properties: ConsensusProperties

src/main/kotlin/io/openfuture/chain/core/model/entity/block/Block.kt

+17
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,23 @@ abstract class Block(
4646

4747
return ByteUtils.toHexString(HashUtils.doubleSha256(bytes))
4848
}
49+
50+
fun generateHashForTransaction(timestamp: Long,
51+
fee: Long, amount: Long,
52+
senderAddress: String,
53+
recipientAddress: String): String {
54+
val bytes = ByteBuffer.allocate(SIZE_BYTES + SIZE_BYTES + SIZE_BYTES +
55+
senderAddress.toByteArray().size + recipientAddress.toByteArray().size)
56+
.putLong(timestamp)
57+
.putLong(fee)
58+
.put(senderAddress.toByteArray())
59+
.putLong(amount)
60+
.put(recipientAddress.toByteArray())
61+
.array()
62+
63+
return ByteUtils.toHexString(HashUtils.doubleSha256(bytes))
64+
}
65+
4966
}
5067

5168

src/main/kotlin/io/openfuture/chain/core/service/block/DefaultBlockManager.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import org.springframework.stereotype.Service
1313
import org.springframework.transaction.annotation.Transactional
1414

1515
@Service
16-
@Transactional(readOnly = true)
16+
@Transactional
1717
class DefaultBlockManager(
1818
private val repository: BlockRepository<Block>,
1919
private val genesisBlockService: GenesisBlockService,

src/main/kotlin/io/openfuture/chain/core/service/block/DefaultBlockService.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired
99
import org.springframework.data.domain.Page
1010
import org.springframework.transaction.annotation.Transactional
1111

12-
@Transactional(readOnly = true)
12+
@Transactional
1313
abstract class DefaultBlockService<T : Block>(
1414
private val repository: BlockRepository<T>
1515
) : BlockService<T> {

src/main/kotlin/io/openfuture/chain/core/service/block/DefaultGenesisBlockService.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import org.springframework.stereotype.Service
2020
import org.springframework.transaction.annotation.Transactional
2121

2222
@Service
23-
@Transactional(readOnly = true)
23+
@Transactional
2424
class DefaultGenesisBlockService(
2525
private val repository: GenesisBlockRepository,
2626
private val stateManager: StateManager,

src/main/kotlin/io/openfuture/chain/core/service/block/DefaultMainBlockService.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import org.springframework.transaction.annotation.Transactional
3737
import kotlin.math.max
3838

3939
@Service
40-
@Transactional(readOnly = true)
40+
@Transactional
4141
class DefaultMainBlockService(
4242
private val repository: MainBlockRepository,
4343
private val stateManager: StateManager,

src/main/kotlin/io/openfuture/chain/core/service/block/validation/BlockValidator.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import org.slf4j.Logger
1313
import org.slf4j.LoggerFactory
1414
import org.springframework.transaction.annotation.Transactional
1515

16-
@Transactional(readOnly = true)
16+
@Transactional
1717
abstract class BlockValidator {
1818

1919
companion object {

src/main/kotlin/io/openfuture/chain/core/service/block/validation/MainBlockValidator.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import org.springframework.stereotype.Service
2525
import org.springframework.transaction.annotation.Transactional
2626

2727
@Service
28-
@Transactional(readOnly = true)
28+
@Transactional
2929
class MainBlockValidator(
3030
private val consensusProperties: ConsensusProperties,
3131
private val stateManager: StateManager,

src/main/kotlin/io/openfuture/chain/core/service/receipt/DefaultReceiptService.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import org.springframework.stereotype.Service
1212
import org.springframework.transaction.annotation.Transactional
1313

1414
@Service
15-
@Transactional(readOnly = true)
15+
@Transactional
1616
class DefaultReceiptService(
1717
private val repository: ReceiptRepository
1818
) : ReceiptService {

src/main/kotlin/io/openfuture/chain/core/service/state/DefaultAccountStateService.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import org.springframework.stereotype.Service
1010
import org.springframework.transaction.annotation.Transactional
1111

1212
@Service
13-
@Transactional(readOnly = true)
13+
@Transactional
1414
class DefaultAccountStateService(
1515
private val repository: AccountStateRepository,
1616
private val statePool: StatePool

src/main/kotlin/io/openfuture/chain/core/service/state/DefaultDelegateStateService.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import org.springframework.stereotype.Service
1313
import org.springframework.transaction.annotation.Transactional
1414

1515
@Service
16-
@Transactional(readOnly = true)
16+
@Transactional
1717
class DefaultDelegateStateService(
1818
private val repository: DelegateStateRepository,
1919
private val consensusProperties: ConsensusProperties,

src/main/kotlin/io/openfuture/chain/core/service/state/DefaultStateManager.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import org.springframework.stereotype.Service
2020
import org.springframework.transaction.annotation.Transactional
2121

2222
@Service
23-
@Transactional(readOnly = true)
23+
@Transactional
2424
class DefaultStateManager(
2525
private val repository: StateRepository<State>,
2626
private val accountStateService: AccountStateService,

src/main/kotlin/io/openfuture/chain/core/service/state/DefaultStateService.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import io.openfuture.chain.core.repository.StateRepository
55
import io.openfuture.chain.core.service.StateService
66
import org.springframework.transaction.annotation.Transactional
77

8-
@Transactional(readOnly = true)
8+
@Transactional
99
abstract class DefaultStateService<T : State>(
1010
private val repository: StateRepository<T>
1111
) : StateService<T> {

src/main/kotlin/io/openfuture/chain/core/service/transaction/DefaultTransactionManager.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import org.springframework.stereotype.Service
2020
import org.springframework.transaction.annotation.Transactional
2121

2222
@Service
23-
@Transactional(readOnly = true)
23+
@Transactional
2424
class DefaultTransactionManager(
2525
private val repository: TransactionRepository<Transaction>,
2626
private val uRepository: UTransactionRepository<UnconfirmedTransaction>,

src/main/kotlin/io/openfuture/chain/core/service/transaction/confirmed/DefaultDelegateTransactionService.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import org.springframework.stereotype.Service
1111
import org.springframework.transaction.annotation.Transactional
1212

1313
@Service
14-
@Transactional(readOnly = true)
14+
@Transactional
1515
class DefaultDelegateTransactionService(
1616
private val repository: DelegateTransactionRepository,
1717
private val consensusProperties: ConsensusProperties

src/main/kotlin/io/openfuture/chain/core/service/transaction/confirmed/DefaultExternalTransactionService.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import io.openfuture.chain.core.service.ExternalTransactionService
99
import org.springframework.beans.factory.annotation.Autowired
1010
import org.springframework.transaction.annotation.Transactional
1111

12-
@Transactional(readOnly = true)
12+
@Transactional
1313
abstract class DefaultExternalTransactionService<T : Transaction>(
1414
private val repository: TransactionRepository<T>
1515
) : DefaultTransactionService<T>(repository), ExternalTransactionService<T> {

src/main/kotlin/io/openfuture/chain/core/service/transaction/confirmed/DefaultRewardTransactionService.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import org.springframework.stereotype.Service
1717
import org.springframework.transaction.annotation.Transactional
1818

1919
@Service
20-
@Transactional(readOnly = true)
20+
@Transactional
2121
class DefaultRewardTransactionService(
2222
private val repository: RewardTransactionRepository,
2323
private val consensusProperties: ConsensusProperties,

src/main/kotlin/io/openfuture/chain/core/service/transaction/confirmed/DefaultTransactionService.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired
1212
import org.springframework.data.domain.Page
1313
import org.springframework.transaction.annotation.Transactional
1414

15-
@Transactional(readOnly = true)
15+
@Transactional
1616
abstract class DefaultTransactionService<T : Transaction>(
1717
private val repository: TransactionRepository<T>
1818
) : TransactionService<T> {

src/main/kotlin/io/openfuture/chain/core/service/transaction/confirmed/DefaultTransferTransactionService.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import org.springframework.stereotype.Service
2424
import org.springframework.transaction.annotation.Transactional
2525

2626
@Service
27-
@Transactional(readOnly = true)
27+
@Transactional
2828
class DefaultTransferTransactionService(
2929
private val repository: TransferTransactionRepository,
3030
private val contractService: ContractService,

src/main/kotlin/io/openfuture/chain/core/service/transaction/confirmed/DefaultVoteTransactionService.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import org.springframework.stereotype.Service
1414
import org.springframework.transaction.annotation.Transactional
1515

1616
@Service
17-
@Transactional(readOnly = true)
17+
@Transactional
1818
class DefaultVoteTransactionService(
1919
private val repository: VoteTransactionRepository,
2020
private val consensusProperties: ConsensusProperties

src/main/kotlin/io/openfuture/chain/core/service/transaction/unconfirmed/DefaultUDelegateTransactionService.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import org.springframework.stereotype.Service
88
import org.springframework.transaction.annotation.Transactional
99

1010
@Service
11-
@Transactional(readOnly = true)
11+
@Transactional
1212
class DefaultUDelegateTransactionService(
1313
uRepository: UDelegateTransactionRepository,
1414
jdbcRepository: UTransactionsJdbcRepository

src/main/kotlin/io/openfuture/chain/core/service/transaction/unconfirmed/DefaultUTransactionService.kt

+21-11
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import io.openfuture.chain.rpc.domain.base.PageRequest
2424
import org.springframework.beans.factory.annotation.Autowired
2525
import org.springframework.transaction.annotation.Transactional
2626

27-
@Transactional(readOnly = true)
27+
@Transactional
2828
abstract class DefaultUTransactionService<uT : UnconfirmedTransaction>(
2929
private val uRepository: UTransactionRepository<uT>,
3030
private val jdbcRepository: UTransactionsJdbcRepository
@@ -66,6 +66,7 @@ abstract class DefaultUTransactionService<uT : UnconfirmedTransaction>(
6666

6767
@BlockchainSynchronized
6868
@Transactional
69+
@Synchronized
6970
override fun add(uTx: uT, unconfirmedBalance: Long): uT {
7071
BlockchainLock.writeLock.lock()
7172
try {
@@ -95,18 +96,27 @@ abstract class DefaultUTransactionService<uT : UnconfirmedTransaction>(
9596
else -> throw IllegalStateException("Wrong type")
9697
}
9798

99+
val findOneByHash = uRepository.findOneByHash(uTx.hash)
100+
if (null != findOneByHash) {
101+
print("Tried to save duplicate")
102+
}
103+
104+
val savedUtx = uRepository.saveAndFlush(uTx)
105+
networkService.broadcast(savedUtx.toMessage())
106+
return savedUtx
107+
98108
//
99109

100-
return if (uTx is UnconfirmedTransferTransaction) {
101-
val savedUtx = jdbcRepository.save(uTx)
102-
networkService.broadcast(savedUtx.toMessage())
103-
uTx.id = savedUtx.id
104-
return uTx
105-
} else {
106-
val savedUtx = uRepository.saveAndFlush(uTx)
107-
networkService.broadcast(savedUtx.toMessage())
108-
savedUtx
109-
}
110+
// return if (uTx is UnconfirmedTransferTransaction) {
111+
// val savedUtx = jdbcRepository.save(uTx)
112+
// networkService.broadcast(savedUtx.toMessage())
113+
// uTx.id = savedUtx.id
114+
// return uTx
115+
// } else {
116+
// val savedUtx = uRepository.saveAndFlush(uTx)
117+
// networkService.broadcast(savedUtx.toMessage())
118+
// savedUtx
119+
// }
110120

111121
} finally {
112122
BlockchainLock.writeLock.unlock()

src/main/kotlin/io/openfuture/chain/core/service/transaction/unconfirmed/DefaultUTransferTransactionService.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import org.springframework.stereotype.Service
88
import org.springframework.transaction.annotation.Transactional
99

1010
@Service
11-
@Transactional(readOnly = true)
11+
@Transactional
1212
class DefaultUTransferTransactionService(
1313
uRepository: UTransferTransactionRepository,
1414
jdbcRepository: UTransactionsJdbcRepository

src/main/kotlin/io/openfuture/chain/core/service/transaction/unconfirmed/DefaultUVoteTransactionService.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import org.springframework.stereotype.Service
1010
import org.springframework.transaction.annotation.Transactional
1111

1212
@Service
13-
@Transactional(readOnly = true)
13+
@Transactional
1414
class DefaultUVoteTransactionService(
1515
private val uRepository: UVoteTransactionRepository,
1616
jdbcRepository: UTransactionsJdbcRepository

src/main/kotlin/io/openfuture/chain/core/service/transaction/validation/DelegateTransactionValidator.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import org.springframework.stereotype.Service
1111
import org.springframework.transaction.annotation.Transactional
1212

1313
@Service
14-
@Transactional(readOnly = true)
14+
@Transactional
1515
class DelegateTransactionValidator(
1616
private val consensusProperties: ConsensusProperties,
1717
private val uRepository: UDelegateTransactionRepository

src/main/kotlin/io/openfuture/chain/core/service/transaction/validation/RewardTransactionValidator.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import org.springframework.stereotype.Service
55
import org.springframework.transaction.annotation.Transactional
66

77
@Service
8-
@Transactional(readOnly = true)
8+
@Transactional
99
class RewardTransactionValidator : TransactionValidator() {
1010

1111
fun check(): Array<TransactionValidateHandler> = arrayOf(

src/main/kotlin/io/openfuture/chain/core/service/transaction/validation/TransactionValidator.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import org.slf4j.LoggerFactory
1919
import org.springframework.beans.factory.annotation.Autowired
2020
import org.springframework.transaction.annotation.Transactional
2121

22-
@Transactional(readOnly = true)
22+
@Transactional
2323
abstract class TransactionValidator {
2424

2525
@Autowired private lateinit var cryptoService: CryptoService

src/main/kotlin/io/openfuture/chain/core/service/transaction/validation/TransferTransactionValidator.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import org.springframework.stereotype.Service
1515
import org.springframework.transaction.annotation.Transactional
1616

1717
@Service
18-
@Transactional(readOnly = true)
18+
@Transactional
1919
class TransferTransactionValidator(
2020
private val contractService: ContractService
2121
) : TransactionValidator() {

src/main/kotlin/io/openfuture/chain/core/service/transaction/validation/VoteTransactionValidator.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import org.springframework.stereotype.Service
1414
import org.springframework.transaction.annotation.Transactional
1515

1616
@Service
17-
@Transactional(readOnly = true)
17+
@Transactional
1818
class VoteTransactionValidator(
1919
private val consensusProperties: ConsensusProperties,
2020
private val uRepository: UVoteTransactionRepository

src/main/kotlin/io/openfuture/chain/network/component/ChannelsHolder.kt

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class ChannelsHolder(
112112
.minus(regularAddresses)
113113
val addresses = regularAddresses.plus(bootAddresses).shuffled()
114114
for (address in addresses) {
115+
log.info("$addresses")
115116
val connected = connectionService.connect(address, Consumer {
116117
greet(it)
117118
})

src/main/kotlin/io/openfuture/chain/rpc/controller/base/ExceptionRestControllerAdvice.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import io.openfuture.chain.core.exception.ValidationException
77
import io.openfuture.chain.rpc.domain.ExceptionResponse
88
import io.openfuture.chain.rpc.domain.ValidationErrorResponse
99
import org.apache.commons.lang3.StringUtils.EMPTY
10-
import org.h2.jdbc.JdbcSQLIntegrityConstraintViolationException
1110
import org.springframework.http.HttpStatus.BAD_REQUEST
1211
import org.springframework.http.HttpStatus.NOT_FOUND
1312
import org.springframework.web.bind.MethodArgumentNotValidException
@@ -66,8 +65,8 @@ class ExceptionRestControllerAdvice {
6665
}
6766

6867
@ResponseStatus(BAD_REQUEST)
69-
@ExceptionHandler(JdbcSQLIntegrityConstraintViolationException::class)
70-
fun handleJdbcSQLIntegrityConstraintViolationException(ex: JdbcSQLIntegrityConstraintViolationException): ExceptionResponse {
68+
@ExceptionHandler(org.hibernate.exception.ConstraintViolationException::class)
69+
fun handleJdbcSQLIntegrityConstraintViolationException(ex: org.hibernate.exception.ConstraintViolationException): ExceptionResponse {
7170
return ExceptionResponse(BAD_REQUEST.value(), ex.message)
7271
}
7372

0 commit comments

Comments
 (0)