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

Quickfix Rhone hashrate #548

Merged
merged 2 commits into from
Jun 12, 2024
Merged
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
33 changes: 33 additions & 0 deletions app/src/main/scala/org/alephium/explorer/Consensus.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2018 The Alephium Authors
// This file is part of the alephium project.
//
// The library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the library. If not, see <http://www.gnu.org/licenses/>.

package org.alephium.explorer

import org.alephium.util.{Duration, TimeStamp}

object Consensus {
// TODO Add this to config
// scalastyle:off magic.number
val rhoneHardForkTimestamp: TimeStamp = TimeStamp.unsafe(1718186400000L)

def blockTargetTime(timestamp: TimeStamp): Duration =
if (timestamp.isBefore(rhoneHardForkTimestamp)) {
Duration.ofSecondsUnsafe(64)
} else {
Duration.ofSecondsUnsafe(16)
}
// scalastyle:on magic.number
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import org.alephium.api.model.{
MultipleCallContractResult,
SelfClique
}
import org.alephium.explorer.GroupSetting
import org.alephium.explorer.{Consensus, GroupSetting}
import org.alephium.explorer.RichAVector._
import org.alephium.explorer.api.model._
import org.alephium.explorer.error.ExplorerError
Expand All @@ -63,7 +63,7 @@ import org.alephium.protocol.model.{
TransactionId
}
import org.alephium.protocol.vm.LockupScript
import org.alephium.util.{AVector, Duration, Hex, Service, TimeStamp, U256}
import org.alephium.util.{AVector, Hex, Service, TimeStamp, U256}

trait BlockFlowClient extends Service {
def fetchBlock(fromGroup: GroupIndex, hash: BlockHash): Future[BlockEntity]
Expand Down Expand Up @@ -550,7 +550,7 @@ object BlockFlowClient extends StrictLogging {
block.depStateHash,
block.txsHash,
block.target,
computeHashRate(block.target)
computeHashRate(block.target, block.timestamp)
)
}
// scalastyle:on null
Expand Down Expand Up @@ -780,11 +780,10 @@ object BlockFlowClient extends StrictLogging {
)
}

// scalastyle:off magic.number
def computeHashRate(targetBytes: ByteString)(implicit groupSetting: GroupSetting): BigInteger = {
val target = Target.unsafe(targetBytes)
val blockTargetTime = Duration.ofSecondsUnsafe(64) // TODO add this to config
HashRate.from(target, blockTargetTime)(groupSetting.groupConfig).value
def computeHashRate(targetBytes: ByteString, timestamp: TimeStamp)(implicit
groupSetting: GroupSetting
): BigInteger = {
val target = Target.unsafe(targetBytes)
HashRate.from(target, Consensus.blockTargetTime(timestamp))(groupSetting.groupConfig).value
}
// scalastyle:on magic.number
}
Loading