diff --git a/libwhisper/WhisperHost.cpp b/libwhisper/WhisperHost.cpp index f9ff33658..4a1f4c8b4 100644 --- a/libwhisper/WhisperHost.cpp +++ b/libwhisper/WhisperHost.cpp @@ -68,7 +68,7 @@ void WhisperHost::inject(Envelope const& _m, WhisperPeer* _p) m_expiryQueue.insert(make_pair(_m.expiry(), h)); } - int rating = 1; // rating for local host is based upon: 1. installed watch; 2. proof of work + int rating = 1; // rating for local host is based upon: 1. installed watch; 2. ttl; 3. proof of work if (_p) // incoming message from remote peer DEV_GUARDED(m_filterLock) diff --git a/libwhisper/WhisperPeer.cpp b/libwhisper/WhisperPeer.cpp index 393c3749c..27662926e 100644 --- a/libwhisper/WhisperPeer.cpp +++ b/libwhisper/WhisperPeer.cpp @@ -121,17 +121,22 @@ unsigned WhisperPeer::ratingForPeer(Envelope const& e) const { // we try to estimate, how valuable this nessage will be for the remote peer, // according to the following criteria: - // 1. bloom filter - // 2. proof of work + // 1. bloom filter + // 2. time to live + // 3. proof of work - static const unsigned BloomFilterMatchReward = 256; // vlad todo: move to common.h unsigned rating = 0; DEV_GUARDED(x_bloom) if (e.matchesBloomFilter(m_bloom)) - rating += BloomFilterMatchReward; - - rating += e.sha3().firstBitSet(); + ++rating; + + rating *= 256; + unsigned ttlReward = (256 > e.ttl() ? 256 - e.ttl() : 0); + rating += ttlReward; + + rating *= 256; + rating += e.workProved(); return rating; } diff --git a/test/libwhisper/whisperMessage.cpp b/test/libwhisper/whisperMessage.cpp index 343573713..1db3352ac 100644 --- a/test/libwhisper/whisperMessage.cpp +++ b/test/libwhisper/whisperMessage.cpp @@ -89,4 +89,18 @@ BOOST_AUTO_TEST_CASE(seal) sealAndOpenSingleMessage(i); } +BOOST_AUTO_TEST_CASE(work) +{ + VerbosityHolder setTemporaryLevel(10); + cnote << "Testing proof of work..."; + + Secret zero; + Topics topics = createRandomTopics(0xDEAD); + bytes const payload = createRandomPayload(0xFFFFF); + Message m(payload); + Envelope e = m.seal(zero, topics, 1, 50); + unsigned x = e.workProved(); + BOOST_REQUIRE(x > 0); +} + BOOST_AUTO_TEST_SUITE_END()