Skip to content
Permalink
Browse files

remove codes about USER_DEFINED_COINBASE

  • Loading branch information
SwimmingTiger committed Oct 27, 2019
1 parent 8eada0c commit 96792fe3baa3502e5cf8ad22a99a42bf1c183a19
@@ -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
###
@@ -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
@@ -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/
@@ -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
@@ -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}

This file was deleted.

@@ -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`. |

@@ -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`. |

@@ -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.

@@ -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)
------------------

This file was deleted.

@@ -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_
});
};
@@ -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];

@@ -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.
@@ -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_;
};
@@ -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);
@@ -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_,
@@ -365,12 +365,7 @@ void StratumMinerBitcoin::handleRequest_Submit(
server.sendShare2Kafka(chainId, message.data(), message.size());
}
}
}
#ifdef USER_DEFINED_COINBASE
,
&localJob->userCoinbaseInfo_
#endif
);
});
}
}

0 comments on commit 96792fe

Please sign in to comment.
You can’t perform that action at this time.