@ -916,26 +916,34 @@ public class Block {
expandedAccounts . add ( rewardShareData ) ;
expandedAccounts . add ( rewardShareData ) ;
}
}
// Possibly check signatures if block is recen t
// If block is past a certain age then we simply assume the signatures were correc t
long signatureRequirementThreshold = NTP . getTime ( ) - BlockChain . getInstance ( ) . getOnlineAccountSignaturesMinLifetime ( ) ;
long signatureRequirementThreshold = NTP . getTime ( ) - BlockChain . getInstance ( ) . getOnlineAccountSignaturesMinLifetime ( ) ;
if ( this . blockData . getTimestamp ( ) > = signatureRequirementThreshold ) {
if ( this . blockData . getTimestamp ( ) < signatureRequirementThreshold )
if ( this . blockData . getOnlineAccountsSignatures ( ) = = null | | this . blockData . getOnlineAccountsSignatures ( ) . length = = 0 )
return ValidationResult . OK ;
return ValidationResult . ONLINE_ACCOUNT_SIGNATURES_MISSING ;
if ( this . blockData . getOnlineAccountsSignatures ( ) . length ! = expandedAccounts . size ( ) * Transformer . SIGNATURE_LENGTH )
if ( this . blockData . getOnlineAccountsSignatures ( ) = = null | | this . blockData . getOnlineAccountsSignatures ( ) . length = = 0 )
return ValidationResult . ONLINE_ACCOUNT_SIGNATURES_MALFORMED ;
return ValidationResult . ONLINE_ACCOUNT_SIGNATURES_MISSING ;
// Check signatures
if ( this . blockData . getOnlineAccountsSignatures ( ) . length ! = expandedAccounts . size ( ) * Transformer . SIGNATURE_LENGTH )
List < byte [ ] > onlineAccountsSignatures = BlockTransformer . decodeTimestampSignatures ( this . blockData . getOnlineAccountsSignatures ( ) ) ;
return ValidationResult . ONLINE_ACCOUNT_SIGNATURES_MALFORMED ;
byte [ ] message = Longs . toByteArray ( this . blockData . getOnlineAccountsTimestamp ( ) ) ;
for ( int i = 0 ; i < onlineAccountsSignatures . size ( ) ; + + i ) {
// Check signatures
PublicKeyAccount account = new PublicKeyAccount ( null , expandedAccounts . get ( i ) . getRewardSharePublicKey ( ) ) ;
List < byte [ ] > onlineAccountsSignatures = BlockTransformer . decodeTimestampSignatures ( this . blockData . getOnlineAccountsSignatures ( ) ) ;
byte [ ] signature = onlineAccountsSignatures . get ( i ) ;
long onlineTimestamp = this . blockData . getOnlineAccountsTimestamp ( ) ;
byte [ ] onlineTimestampBytes = Longs . toByteArray ( onlineTimestamp ) ;
List < OnlineAccountData > onlineAccounts = Controller . getInstance ( ) . getOnlineAccounts ( ) ;
if ( ! account . verify ( signature , message ) )
for ( int i = 0 ; i < onlineAccountsSignatures . size ( ) ; + + i ) {
return ValidationResult . ONLINE_ACCOUNT_SIGNATURE_INCORRECT ;
byte [ ] signature = onlineAccountsSignatures . get ( i ) ;
}
byte [ ] publicKey = expandedAccounts . get ( i ) . getRewardSharePublicKey ( ) ;
// If signature is still current then no need to perform Ed25519 verify
OnlineAccountData onlineAccountData = new OnlineAccountData ( onlineTimestamp , signature , publicKey ) ;
if ( onlineAccounts . remove ( onlineAccountData ) ) // remove() is like contains() but also reduces the number to check next time
continue ;
if ( ! PublicKeyAccount . verify ( publicKey , signature , onlineTimestampBytes ) )
return ValidationResult . ONLINE_ACCOUNT_SIGNATURE_INCORRECT ;
}
}
return ValidationResult . OK ;
return ValidationResult . OK ;