Skip to content

Adding a shared queue in Socket class#184

Merged
davidtavarez merged 8 commits intomasterfrom
p2p/sharedqueue
Jan 11, 2022
Merged

Adding a shared queue in Socket class#184
davidtavarez merged 8 commits intomasterfrom
p2p/sharedqueue

Conversation

@davidtavarez
Copy link
Copy Markdown
Member

@davidtavarez davidtavarez commented Dec 20, 2021

@davidtavarez davidtavarez added the wip Work in Progress label Dec 20, 2021
@davidtavarez davidtavarez self-assigned this Dec 24, 2021
@davidtavarez davidtavarez removed the wip Work in Progress label Dec 24, 2021
{
const uint8_t version = byteBuffer.ReadU8();
assert(version == 0);
assert(byteBuffer.ReadU8() == 0);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this change. If compiled with NDEBUG (many release builds), anything inside of assertions isn't executed, so it will deserialize incorrectly.

pConnection->SendSync(TxHashSetArchiveMessage{ pHeader->GetHash(), pHeader->GetHeight(), fileSize });

std::vector<uint8_t> buffer(BUFFER_SIZE, 0);
uint64_t totalBytesRead = 0;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove unused code, don't comment it out.

void TxHashSet::SaveOutputPositions(const Chain::CPtr& pChain, std::shared_ptr<IBlockDB> pBlockDB) const
{
uint64_t firstOutput = 0;
// uint64_t firstOutput = 0;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove, don't comment it out.

{
Json::Value outputNode;
const EOutputFeatures features = info.GetIdentifier().GetFeatures();
// const EOutputFeatures features = info.GetIdentifier().GetFeatures();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove, don't comment it out.

for (const WalletTx& walletTx : transactions)
{
sqlite3_stmt* stmt = nullptr;
// sqlite3_stmt* stmt = nullptr;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove, don't comment it out.

TEST_CASE("Bech32Address")
{
uint8_t version = 1;
// uint8_t version = 1;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove, don't comment it out.

SharedQueue<T>::~SharedQueue() {}

template <typename T>
T& SharedQueue<T>::front()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the function implementations into the actual class definition. Otherwise, I think you'll have issues if trying to include this header in multiple places.

template <typename T>
class SharedQueue
{
public:
    SharedQueue() = default;
    ~SharedQueue() = default;

    T& front()
    {
        // implement here
    }

    void pop_front()
    {
        // implement here
    }

    void push_back(const T& item)
    {
        // implement here
    }

    void push_back(T&& item)
    {
        // implement here
    }

    int size()
    {
        // implement here
    }

    bool empty()
    {
        // implement here
    }

private:
    std::deque<T> queue_;
    std::mutex mutex_;
    std::condition_variable cond_;
};

#include <condition_variable>

template <typename T>
class SharedQueue
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this class even needed? Does ConcurrentQueue not do what you need?

Copy link
Copy Markdown
Member Author

@davidtavarez davidtavarez Dec 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConcurrentQueue is subject to race conditions between calls to empty, front and pop if there is more than one thread; we could either use SharedQueue class or edit the ConcurrentQueue class. More here https://www.justsoftwaresolutions.co.uk/threading/implementing-a-thread-safe-queue-using-condition-variables.html

m_writeQueue.push(message);

if (!first_in_queue) {
if (!m_writeQueue.empty()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't correct. Since you aren't adding message to the queue, if something's already being written to the socket, we just drop message.

release_command: 'npm run clean_build:nix && npm run release'
- name: ubuntu
os: ubuntu-16.04
os: ubuntu-18.04
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had some users running older Debian instances, which is why we built with 16.04. We're probably good to update this to 18.04 now, but you should check with the channel first, if you haven't already.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ubuntu 16.04 environment was removed on September 20, 2021 actions/runner-images#3287

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we don't really have a choice then. You'll want to mention that in the next release announcement.

peersToUpdate.push_back(peerEntry.m_peer);
peerEntry.m_peer->SetDirty(false);
} else if (peerEntry.m_peer->GetLastContactTime() > 0 && peerEntry.m_peer->GetLastContactTime() < minimumContactTime) {
peerManager.m_peersByAddress.erase(iter);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

@davidtavarez davidtavarez merged commit 7b43020 into master Jan 11, 2022
@davidtavarez davidtavarez deleted the p2p/sharedqueue branch January 11, 2022 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants