Skip to content

Commit

Permalink
remove codes about USER_DEFINED_COINBASE
Browse files Browse the repository at this point in the history
  • Loading branch information
SwimmingTiger committed Feb 1, 2020
1 parent 8eada0c commit 96792fe
Show file tree
Hide file tree
Showing 14 changed files with 2 additions and 300 deletions.
21 changes: 0 additions & 21 deletions CMakeLists.txt
Expand Up @@ -189,27 +189,6 @@ else()
endif()


###
# user defined coinbase info
###
option(POOL__USER_DEFINED_COINBASE "User Defined Coinbase" OFF)

# the size of user defined coinbase, default is 10 bytes
if (NOT POOL__USER_DEFINED_COINBASE_SIZE)
set(POOL__USER_DEFINED_COINBASE_SIZE 10)
endif()

if (POOL__USER_DEFINED_COINBASE)
message("-- User Defined Coinbase: Enabled (-DPOOL__USER_DEFINED_COINBASE=ON)")
message("-- The Size of User Defined Coinbase: ${POOL__USER_DEFINED_COINBASE_SIZE} Bytes (-DPOOL__USER_DEFINED_COINBASE_SIZE=${POOL__USER_DEFINED_COINBASE_SIZE})")
add_definitions(-DUSER_DEFINED_COINBASE)
add_definitions(-DUSER_DEFINED_COINBASE_SIZE=${POOL__USER_DEFINED_COINBASE_SIZE})
set(POOL__DEB_PACKNAME_POSTFIX "${POOL__DEB_PACKNAME_POSTFIX}-usercoinbase${POOL__USER_DEFINED_COINBASE_SIZE}")
else()
message("-- User Defined Coinbase: Disabled (-DPOOL__USER_DEFINED_COINBASE=OFF)")
endif()


###
# options for install & package
###
Expand Down
4 changes: 0 additions & 4 deletions docker/btcpool/deploy/Dockerfile
Expand Up @@ -16,8 +16,6 @@ ARG GIT_DESCRIBE=""
ARG BUILD_JOBS=1
ARG BUILD_TESTING=ON
ARG BUILD_TYPE=Release
ARG USER_DEFINED_COINBASE=OFF
ARG USER_DEFINED_COINBASE_SIZE=10
ARG WORK_WITH_STRATUM_SWITCHER=OFF

# Copy & build btcpool
Expand All @@ -32,8 +30,6 @@ RUN mkdir -p /tmp/build && cd /tmp/build && cmake \
-DKAFKA_LINK_STATIC=ON \
-DPOOL__GENERATE_DEB_PACKAGE=ON \
-DPOOL__INSTALL_PREFIX=/work/btcpool \
-DPOOL__USER_DEFINED_COINBASE_SIZE=${USER_DEFINED_COINBASE_SIZE} \
-DPOOL__USER_DEFINED_COINBASE=${USER_DEFINED_COINBASE} \
-DPOOL__WORK_WITH_STRATUM_SWITCHER=${WORK_WITH_STRATUM_SWITCHER} \
/tmp/btcpool
RUN cd /tmp/build && make package -j${BUILD_JOBS} && mkdir -p /work/package && cp *.deb /work/package/
Expand Down
4 changes: 0 additions & 4 deletions docker/btcpool/test/Dockerfile
Expand Up @@ -16,8 +16,6 @@ ARG GIT_DESCRIBE=""
ARG BUILD_JOBS=1
ARG BUILD_TESTING=ON
ARG BUILD_TYPE=Release
ARG USER_DEFINED_COINBASE=OFF
ARG USER_DEFINED_COINBASE_SIZE=10
ARG WORK_WITH_STRATUM_SWITCHER=OFF

# Copy & build btcpool
Expand All @@ -32,8 +30,6 @@ RUN mkdir -p /work/btcpool/build && cd /work/btcpool/build && cmake \
-DKAFKA_LINK_STATIC=ON \
-DPOOL__GENERATE_DEB_PACKAGE=ON \
-DPOOL__INSTALL_PREFIX=/work/btcpool \
-DPOOL__USER_DEFINED_COINBASE_SIZE=${USER_DEFINED_COINBASE_SIZE} \
-DPOOL__USER_DEFINED_COINBASE=${USER_DEFINED_COINBASE} \
-DPOOL__WORK_WITH_STRATUM_SWITCHER=${WORK_WITH_STRATUM_SWITCHER} \
/work/btcpool
RUN cd /work/btcpool/build && make -j${BUILD_JOBS}
Expand Down

This file was deleted.

2 changes: 0 additions & 2 deletions docs/Eth/INSTALL-ETHPool.md
Expand Up @@ -98,8 +98,6 @@ or link BTCPool with different blockchains.
| CHAIN_SRC_ROOT | A path of dir, such as `/work/bitcoin`. | No default value, you must define it. | The path of blockchain's source code that you want to BTCPool linking to. |
| OPENSSL_ROOT_DIR | A path of dir, such as `/usr/local/opt/openssl`. | No definition is required by default, and cmake will automatically look for it. | The path of `openssl`'s source code. The macOS user may need to define it if cmake cannot find it automatically. |
| POOL__WORK_WITH_STRATUM_SWITCHER | ON, OFF | OFF | Build a special version of pool's stratum server, so you can run it with a stratum switcher. See also: [Stratum Switcher](https://github.com/btccom/stratumSwitcher). |
| POOL__USER_DEFINED_COINBASE | ON, OFF | OFF | Build a special version of pool that allows user-defined content to be inserted into coinbase input. TODO: add documents about it. |
| POOL__USER_DEFINED_COINBASE_SIZE | A number (bytes), from 1 to the maximum length that coinbase input can hold | 10 | The size of user-defined content that inserted into coinbase input. No more than 20 bytes is recommended. |
| POOL__INSTALL_PREFIX | A path of dir, such as `/work/btcpool.btc`. | /work/bitcoin.\[btc\|bch\|sbtc\|ubtc\] | The install path of `make install`. The deb package that generated by `make package` will install to the same path. |
| POOL__GENERATE_DEB_PACKAGE | ON, OFF | OFF | When it enabled, you can generate a deb package with `make package`. |

Expand Down
5 changes: 1 addition & 4 deletions docs/INSTALL-BTCPool.md
Expand Up @@ -108,8 +108,6 @@ or link BTCPool with different blockchains.
| CHAIN_SRC_ROOT | A path of dir, such as `/work/bitcoin`. | No default value, you must define it. | The path of blockchain's source code that you want to BTCPool linking to. |
| OPENSSL_ROOT_DIR | A path of dir, such as `/usr/local/opt/openssl`. | No definition is required by default, and cmake will automatically look for it. | The path of `openssl`'s source code. The macOS user may need to define it if cmake cannot find it automatically. |
| POOL__WORK_WITH_STRATUM_SWITCHER | ON, OFF | OFF | Build a special version of pool's stratum server, so you can run it with a stratum switcher. See also: [Stratum Switcher](https://github.com/btccom/btcpool-go-modules/stratumSwitcher). |
| POOL__USER_DEFINED_COINBASE | ON, OFF | OFF | Build a special version of pool that allows user-defined content to be inserted into coinbase input. TODO: add documents about it. |
| POOL__USER_DEFINED_COINBASE_SIZE | A number (bytes), from 1 to the maximum length that coinbase input can hold | 10 | The size of user-defined content that inserted into coinbase input. No more than 20 bytes is recommended. |
| POOL__INSTALL_PREFIX | A path of dir, such as `/work/btcpool.btc`. | /work/bitcoin.\[btc\|bch\|sbtc\|ubtc\] | The install path of `make install`. The deb package that generated by `make package` will install to the same path. |
| POOL__GENERATE_DEB_PACKAGE | ON, OFF | OFF | When it enabled, you can generate a deb package with `make package`. |

Expand Down Expand Up @@ -416,8 +414,7 @@ $ curl http://xxx.xxx.xxx/GetUserList?last_id=8

There is a demo for the API: https://github.com/btccom/btcpool/issues/16#issuecomment-278245381

There are more reference implementations here, including a user list with automatic registration enabled
and a user list with `POOL__USER_DEFINED_COINBASE=ON`: [install/api-sample](../install/api-sample)
There are more reference implementations here, including a user list with automatic registration enabled.

### use `supervisor` to manager services.

Expand Down
6 changes: 0 additions & 6 deletions install/api-sample/README.md
Expand Up @@ -22,12 +22,6 @@ It is used with the `userlist-autoreg.php` above.
[autoreg.php](autoreg.php)


### User List with `POOL__USER_DEFINED_COINBASE=ON`

[user-list-coinbase-withtime](user-list-coinbase-withtime)



`UserCoinMapURL` in [Switcher API Server](https://github.com/btccom/btcpool-go-modules/tree/master/switcherAPIServer)
------------------

Expand Down
47 changes: 0 additions & 47 deletions install/api-sample/user-list-coinbase-withtime.php

This file was deleted.

104 changes: 0 additions & 104 deletions src/UserInfo.cc
Expand Up @@ -75,10 +75,6 @@ UserInfo::UserInfo(StratumServer *server, const libconfig::Config &config)
std::make_unique<std::shared_timed_mutex>(), // rwlock_
{}, // nameIds_
0, // lastMaxUserId_
#ifdef USER_DEFINED_COINBASE
{}, // idCoinbaseInfos_
0, // lastTime_
#endif
{} // threadUpdate_
});
};
Expand Down Expand Up @@ -347,103 +343,6 @@ int32_t UserInfo::getUserId(size_t chainId, const string &userName) {
return 0; // not found
}

#ifdef USER_DEFINED_COINBASE
////////////////////// User defined coinbase enabled //////////////////////

// getCoinbaseInfo
string UserInfo::getCoinbaseInfo(size_t chainId, int32_t userId) {
ChainVars &chain = chains_[chainId];
pthread_rwlock_rdlock(&chain.nameIdlock_);
auto itr = chain.idCoinbaseInfos_.find(userId);
pthread_rwlock_unlock(&chain.nameIdlock_);

if (itr != chain.idCoinbaseInfos_.end()) {
return itr->second;
}
return ""; // not found
}

int32_t UserInfo::incrementalUpdateUsers(size_t chainId) {
ChainVars &chain = chains_[chainId];

//
// WARNING: The API is incremental update, we use `?last_id=*&last_time=*` to
// make sure
// always get the new data. Make sure you have use `last_id` and
// `last_time` in API.
//
const string url = Strings::Format(
"%s?last_id=%d&last_time=%d",
chain.apiUrl_,
chain.lastMaxUserId_,
chain.lastTime_);
string resp;
if (!httpGET(url.c_str(), resp, 10000 /* timeout ms */)) {
LOG(ERROR) << "http get request user list fail, url: " << url;
return -1;
}

JsonNode r;
if (!JsonNode::parse(resp.c_str(), resp.c_str() + resp.length(), r)) {
LOG(ERROR) << "decode json fail, json: " << resp;
return -1;
}
if (r["data"].type() == Utilities::JS::type::Undefined) {
LOG(ERROR) << "invalid data, should key->value, type: "
<< (int)r["data"].type();
return -1;
}
JsonNode data = r["data"];

auto vUser = data["users"].children();
if (vUser->size() == 0) {
return 0;
}
chain.lastTime_ = data["time"].int64();

pthread_rwlock_wrlock(&chain.nameIdlock_);
for (JsonNode &itr : *vUser) {

string userName = itr.key();
regularUserName(userName);

if (itr.type() != Utilities::JS::type::Obj) {
LOG(ERROR) << "invalid data, should key - value" << std::endl;
return -1;
}

int32 userId = itr["puid"].int32();
string coinbaseInfo = itr["coinbase"].str();

// resize coinbaseInfo to USER_DEFINED_COINBASE_SIZE bytes
if (coinbaseInfo.size() > USER_DEFINED_COINBASE_SIZE) {
coinbaseInfo.resize(USER_DEFINED_COINBASE_SIZE);
} else {
// padding '\x20' at both beginning and ending of coinbaseInfo
int beginPaddingLen =
(USER_DEFINED_COINBASE_SIZE - coinbaseInfo.size()) / 2;
coinbaseInfo.insert(0, beginPaddingLen, '\x20');
coinbaseInfo.resize(USER_DEFINED_COINBASE_SIZE, '\x20');
}

if (userId > chain.lastMaxUserId_) {
chain.lastMaxUserId_ = userId;
}
chain.nameIds_[userName] = userId;

// get user's coinbase info
LOG(INFO) << "user id: " << userId << ", coinbase info: " << coinbaseInfo;
chain.idCoinbaseInfos_[userId] = coinbaseInfo;
}
pthread_rwlock_unlock(&chain.nameIdlock_);

return vUser->size();
}

/////////////////// End of user defined coinbase enabled ///////////////////
#else
////////////////////// User defined coinbase disabled //////////////////////

int32_t UserInfo::incrementalUpdateUsers(size_t chainId) {
ChainVars &chain = chains_[chainId];

Expand Down Expand Up @@ -492,9 +391,6 @@ int32_t UserInfo::incrementalUpdateUsers(size_t chainId) {
return vUser->size();
}

/////////////////// End of user defined coinbase disabled ///////////////////
#endif

void UserInfo::runThreadUpdate(size_t chainId) {
//
// get all user list, incremental update model.
Expand Down
8 changes: 0 additions & 8 deletions src/UserInfo.h
Expand Up @@ -56,11 +56,6 @@ class UserInfo {
// username -> userId
std::unordered_map<string, int32_t> nameIds_;
int32_t lastMaxUserId_;
#ifdef USER_DEFINED_COINBASE
// userId -> userCoinbaseInfo
std::unordered_map<int32_t, string> idCoinbaseInfos_;
int64_t lastTime_;
#endif

thread threadUpdate_;
};
Expand Down Expand Up @@ -122,9 +117,6 @@ class UserInfo {
// If only one chain, chainId=0 and true will always be returned.
bool getChainId(const string &userName, size_t &chainId);
int32_t getUserId(size_t chainId, const string &userName);
#ifdef USER_DEFINED_COINBASE
string getCoinbaseInfo(size_t chainId, int32_t userId);
#endif

bool autoRegEnabled() const { return enableAutoReg_; }
bool tryAutoReg(string userName, uint32_t sessionId, string fullWorkerName);
Expand Down
10 changes: 0 additions & 10 deletions src/bitcoin/StratumBitcoin.cc
Expand Up @@ -676,16 +676,6 @@ bool StratumJobBitcoin::initFromGbt(
cbIn.scriptSig.end(), mergedMiningBin.begin(), mergedMiningBin.end());
}

#ifdef USER_DEFINED_COINBASE
// reserved for user defined coinbase info
string userCoinbaseInfoPadding;
userCoinbaseInfoPadding.resize(USER_DEFINED_COINBASE_SIZE, '\x20');
cbIn.scriptSig.insert(
cbIn.scriptSig.end(),
userCoinbaseInfoPadding.begin(),
userCoinbaseInfoPadding.end());
#endif

// placeHolder: extra nonce1 (4bytes) + extra nonce2 (8bytes)
const vector<char> placeHolder(
StratumMiner::kExtraNonce1Size_ + StratumMiner::kExtraNonce2Size_,
Expand Down
7 changes: 1 addition & 6 deletions src/bitcoin/StratumMinerBitcoin.cc
Expand Up @@ -365,12 +365,7 @@ void StratumMinerBitcoin::handleRequest_Submit(
server.sendShare2Kafka(chainId, message.data(), message.size());
}
}
}
#ifdef USER_DEFINED_COINBASE
,
&localJob->userCoinbaseInfo_
#endif
);
});
}
}

Expand Down

0 comments on commit 96792fe

Please sign in to comment.